GUI/SplitContainerAdv.cs
author moel.mich
Wed, 22 Sep 2010 19:12:12 +0000
changeset 196 5e9a8595296c
child 344 3145aadca3d2
permissions -rw-r--r--
Rewritten the PCI access for AMD CPUs.
     1 /*
     2   
     3   Version: MPL 1.1/GPL 2.0/LGPL 2.1
     4 
     5   The contents of this file are subject to the Mozilla Public License Version
     6   1.1 (the "License"); you may not use this file except in compliance with
     7   the License. You may obtain a copy of the License at
     8  
     9   http://www.mozilla.org/MPL/
    10 
    11   Software distributed under the License is distributed on an "AS IS" basis,
    12   WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
    13   for the specific language governing rights and limitations under the License.
    14 
    15   The Original Code is the Open Hardware Monitor code.
    16 
    17   The Initial Developer of the Original Code is 
    18   Michael Möller <m.moeller@gmx.ch>.
    19   Portions created by the Initial Developer are Copyright (C) 2009-2010
    20   the Initial Developer. All Rights Reserved.
    21 
    22   Contributor(s):
    23 
    24   Alternatively, the contents of this file may be used under the terms of
    25   either the GNU General Public License Version 2 or later (the "GPL"), or
    26   the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
    27   in which case the provisions of the GPL or the LGPL are applicable instead
    28   of those above. If you wish to allow use of your version of this file only
    29   under the terms of either the GPL or the LGPL, and not to allow others to
    30   use your version of this file under the terms of the MPL, indicate your
    31   decision by deleting the provisions above and replace them with the notice
    32   and other provisions required by the GPL or the LGPL. If you do not delete
    33   the provisions above, a recipient may use your version of this file under
    34   the terms of any one of the MPL, the GPL or the LGPL.
    35  
    36 */
    37 
    38 using System;
    39 using System.Collections.Generic;
    40 using System.Drawing;
    41 using System.Windows.Forms;
    42 
    43 namespace OpenHardwareMonitor.GUI {
    44   public class SplitContainerAdv : SplitContainer {
    45 
    46     private int delta = 0;
    47     private Border3DStyle border3DStyle = Border3DStyle.Raised;
    48     private Color color = SystemColors.Control;
    49 
    50     public SplitContainerAdv()
    51       : base() {
    52       SetStyle(ControlStyles.ResizeRedraw, true);
    53       SetStyle(ControlStyles.AllPaintingInWmPaint, true);
    54       SetStyle(ControlStyles.UserPaint, true);
    55       SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
    56       SetStyle(ControlStyles.ContainerControl, true);
    57       UpdateStyles();
    58     }
    59 
    60     protected override void OnPaint(PaintEventArgs e) {
    61       base.OnPaint(e);
    62 
    63       Graphics g = e.Graphics;
    64       Rectangle r = SplitterRectangle;
    65       using (SolidBrush brush = new SolidBrush(color))
    66         g.FillRectangle(brush, r);
    67       ControlPaint.DrawBorder3D(g, r, border3DStyle);
    68     }
    69 
    70     protected override void OnKeyDown(KeyEventArgs e) {
    71       if (!base.IsSplitterFixed) {
    72         if (e.KeyData == Keys.Right || e.KeyData == Keys.Down) {
    73           SplitterDistance += SplitterIncrement;
    74         } else if (e.KeyData == Keys.Left || e.KeyData == Keys.Up) {
    75           SplitterDistance -= SplitterIncrement;
    76         }
    77         Invalidate();
    78       }
    79     }
    80 
    81     protected override void OnMouseDown(MouseEventArgs e) {
    82       if (Orientation == Orientation.Vertical) {
    83         delta = this.SplitterDistance - e.X;
    84         Cursor.Current = Cursors.VSplit;
    85       } else {
    86         delta = this.SplitterDistance - e.Y;
    87         Cursor.Current = Cursors.HSplit;
    88       }
    89       base.IsSplitterFixed = true;
    90     }
    91 
    92     protected override void OnMouseMove(MouseEventArgs e) {
    93       if (base.IsSplitterFixed) {
    94         if (e.Button == MouseButtons.Left) {
    95           if (Orientation == Orientation.Vertical) {
    96             if (e.X > 0 && e.X < Width) {
    97               SplitterDistance = e.X + delta < 0 ? 0 : e.X + delta;
    98             }
    99           } else {
   100             if (e.Y > 0 && e.Y < Height) {
   101               SplitterDistance = e.Y + delta < 0 ? 0 : e.Y + delta;
   102             }
   103           }
   104         } else {
   105           base.IsSplitterFixed = false;
   106         }
   107         Invalidate();
   108       } else {
   109         if (SplitterRectangle.Contains(e.Location)) {
   110           Cursor = Orientation == Orientation.Vertical ?
   111             Cursors.VSplit : Cursors.HSplit;
   112         }
   113       }
   114     }
   115 
   116     protected override void OnMouseLeave(EventArgs e) {
   117       base.OnMouseLeave(e);
   118       Cursor = Cursors.Default;
   119     }
   120 
   121     protected override void OnMouseUp(MouseEventArgs e) {
   122       delta = 0;
   123       base.IsSplitterFixed = false;
   124       Cursor.Current = Cursors.Default;
   125     }
   126 
   127     public Border3DStyle Border3DStyle {
   128       get { return border3DStyle; }
   129       set {
   130         border3DStyle = value;
   131         Invalidate(false);
   132       }
   133     }
   134 
   135     public Color Color {
   136       get { return color; }
   137       set {
   138         color = value;
   139         Invalidate(false);
   140       }
   141     }
   142 
   143     public new bool IsSplitterFixed {
   144       get {
   145         return false;
   146       }
   147     }
   148 
   149   }
   150 }