// System Metrics - MetricsB - Scrolling Text

using System;
using System.Windows.Forms;

using Calculus;

using IPlusPlus;
using IPlusPlus.Windows;
using IPlusPlus.Graphics;

class MetricEntry
{
    public SystemMetric Index;
    public string Description;

    public MetricEntry(SystemMetric IndexSet,
                       string DescriptionSet)
    {
        Index = IndexSet;
        Description = DescriptionSet;
    }
}

enum Columns { Column1 = 30, Column2 = 40 };

class SystemMetrics : Form
{
    public Array<MetricEntry> Metrics;

    public int WidthOfCharacter;
    public int HeightOfCharacter;
    public int WidthOfCapitals;

    [STAThread]
    public static void Main()
    {
        application.Run(new SystemMetrics());
    }

    SystemMetrics()
    {
        Text = "System Metrics";
        BackColor = System.Drawing.Color.white;

        DeviceContext deviceContext = new DeviceContext(this);

        TextMetrics TextMetricsGet = deviceContext.TextMetrics;

        WidthOfCharacter = TextMetricsGet.AverageCharacterWidth;

        if ((TextMetricsGet.PitchAndFamily & 1) != 0)
            WidthOfCapitals = 3 * WidthOfCharacter / 2;
        else
            WidthOfCapitals = WidthOfCharacter;

        HeightOfCharacter = TextMetricsGet.Height + TextMetricsGet.ExternalLeading;

        Metrics = new Array<MetricEntry>()
                     {
                      new MetricEntry(SystemMetric.ScreenWidth,                        "Screen width in pixels"),
                      new MetricEntry(SystemMetric.ScreenHeight,                       "Screen height in pixels"),
                      new MetricEntry(SystemMetric.VerticalScrollWidth,                "Vertical scroll arrow width"),
                      new MetricEntry(SystemMetric.HorizontalScrollHeight,             "Horizontal scroll arrow height"),
                      new MetricEntry(SystemMetric.CaptionHeight,                      "Caption bar height"),
                      new MetricEntry(SystemMetric.BorderWidth,                        "Window border width"),
                      new MetricEntry(SystemMetric.BorderHeight,                       "Window border height"),
                      new MetricEntry(SystemMetric.FixedFrameWidth,                    "Dialog window frame width"),
                      new MetricEntry(SystemMetric.FixedFrameHeight,                   "Dialog window frame height"),
                      new MetricEntry(SystemMetric.VerticalSliderHeight,               "Vertical scroll thumb height"),
                      new MetricEntry(SystemMetric.HorizontalSliderWidth,              "Horizontal scroll thumb width"),
                      new MetricEntry(SystemMetric.IconWidth,                          "Icon width"),
                      new MetricEntry(SystemMetric.IconHeight,                         "Icon height"),
                      new MetricEntry(SystemMetric.CursorWidth,                        "Cursor width"),
                      new MetricEntry(SystemMetric.CursorHeight,                       "Cursor height"),
                      new MetricEntry(SystemMetric.MenuHeight,                         "Menu bar height"),
                      new MetricEntry(SystemMetric.FullScreenWidth,                    "Full screen client area width"),
                      new MetricEntry(SystemMetric.FullScreenHeight,                   "Full screen client area height"),
                      new MetricEntry(SystemMetric.KanjiWindowHeight,                  "Kanji window height"),
                      new MetricEntry(SystemMetric.MousePresent,                       "Mouse present flag"),
                      new MetricEntry(SystemMetric.VerticalScrollarrowHeight,          "Vertical scroll arrow height"),
                      new MetricEntry(SystemMetric.HorizontalScrollarrowWidth,         "Horizontal scroll arrow width"),
                      new MetricEntry(SystemMetric.Debug,                              "Debug version flag"),
                      new MetricEntry(SystemMetric.SwapButton,                         "Mouse buttons swapped flag"),
                      new MetricEntry(SystemMetric.Reserved1,                          "Reserved"),
                      new MetricEntry(SystemMetric.Reserved2,                          "Reserved"),
                      new MetricEntry(SystemMetric.Reserved3,                          "Reserved"),
                      new MetricEntry(SystemMetric.Reserved4,                          "Reserved"),
                      new MetricEntry(SystemMetric.MinimumWidth,                       "Minimum window width"),
                      new MetricEntry(SystemMetric.MinimumHeight,                      "Minimum window height"),
                      new MetricEntry(SystemMetric.ButtonWidth,                        "Minimize/Maximize icon width"),
                      new MetricEntry(SystemMetric.ButtonHeight,                       "Minimize/Maximize icon height"),
                      new MetricEntry(SystemMetric.SizeFrameWidth,                     "Window frame width"),
                      new MetricEntry(SystemMetric.SizeFrameHeight,                    "Window frame height"),
                      new MetricEntry(SystemMetric.MinimumTrackWidth,                  "Minimum window tracking width"),
                      new MetricEntry(SystemMetric.MinimumTrackHeight,                 "Minimum window tracking height"),
                      new MetricEntry(SystemMetric.DoubleClickWidth,                   "Double click x tolerance"),
                      new MetricEntry(SystemMetric.DoubleClickHeight,                  "Double click y tolerance"),
                      new MetricEntry(SystemMetric.IconSpacingWidth,                   "Horizontal icon spacing"),
                      new MetricEntry(SystemMetric.IconSpacingHeight,                  "Vertical icon spacing"),
                      new MetricEntry(SystemMetric.MenuDropAlignment,                  "Left or right menu drop"),
                      new MetricEntry(SystemMetric.PenWindows,                         "Pen extensions installed"),
                      new MetricEntry(SystemMetric.DoubleByteEnabled,                  "Double-byte char set enabled"),
                      new MetricEntry(SystemMetric.NumberMouseButtons,                 "Number of mouse buttons"),
                      new MetricEntry(SystemMetric.SoundsShow,                         "Present sounds visually")
                     };

        System.Drawing.Size MetricsBounds = new System.Drawing.Size();
        MetricsBounds.Width = WidthOfCharacter + (int)Columns.Column1 * WidthOfCapitals + (int)Columns.Column2 * WidthOfCharacter;
        MetricsBounds.Height = HeightOfCharacter * ((int)Metrics.Length + 1);
        AutoScrollMinSize = MetricsBounds;

        Paint += OnPaint;
        Scroll += OnScroll;
    }

    void OnPaint(object source, PaintEventArgs e)
    {
        DeviceContext deviceContext = new DeviceContext(this);

        HScrollProperties HProperties = HorizontalScroll;
        VScrollProperties VProperties = VerticalScroll;

        for (int i = 0; i < (int)Metrics.Length; i++)
        {
             int x = WidthOfCharacter  * (-HProperties.Value / WidthOfCharacter);
             int y = HeightOfCharacter * (-VProperties.Value / HeightOfCharacter + i);

            deviceContext.TextOut(x,
                                  y,
                                  "SystemMetric." + (Metrics[i].Index).ToString());

            deviceContext.TextOut(x + (int)Columns.Column1 * WidthOfCapitals,
                                  y,
                                  Metrics[i].Description);

            deviceContext.TextAlignment = (int)TextAlignment.Right | (int)TextAlignment.Top;

            deviceContext.TextOut(x + (int)Columns.Column1 * WidthOfCapitals + (int)Columns.Column2 * WidthOfCharacter,
                                  y,
                                  Win.GetSystemMetrics((int)Metrics[i].Index).ToString());

            deviceContext.TextAlignment = (int)TextAlignment.Left | (int)TextAlignment.Top;
        }
    }

    void OnScroll(object source, ScrollEventArgs e)
    {
        Invalidate();
    }
}