using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

using Corp3s.NativeAPI;

namespace Corp3s.Controls
{
    public class NativeWindows
    {        
        private const int GWL_EXSTYLE = -20;
        private const int WS_EX_WINDOWEDGE = 0x00000100;
        private const int WS_EX_CLIENTEDGE = 0x00000200;

        private const int SWP_NOSIZE = 0x0001;
        private const int SWP_NOMOVE = 0x0002;
        private const int SWP_NOZORDER = 0x0004;
        private const int SWP_NOACTIVATE = 0x0010;
        private const int SWP_FRAMECHANGED = 0x0020;

        private const int GWL_STYLE = -16;
        private const int SS_NOTIFY = 0x00000100;
        private const int WS_BORDER = 0x800000;
        private const int ES_NUMBER = 0x2000;

        public static void SetSSNotify(Control control)
        {
#if !DESIGN
            IntPtr hwnd = control.Handle;
            control.Capture = true;
            hwnd = WinAPI.Instance.GetCapture();
            control.Capture = false;

            int nStyle = WinAPI.Instance.GetWindowLong(hwnd, GWL_STYLE);
            WinAPI.Instance.SetWindowLong(hwnd, GWL_STYLE, nStyle | SS_NOTIFY | ES_NUMBER);            
#endif
        }

        public static void SetWindowEdge(Control control)
        {
#if !DESIGN

            IntPtr hwnd = control.Handle;
            control.Capture = true;
            hwnd = WinAPI.Instance.GetCapture();
            control.Capture = false;

            int nStyle = WinAPI.Instance.GetWindowLong(hwnd, GWL_STYLE);
            WinAPI.Instance.SetWindowLong(hwnd, GWL_STYLE, nStyle | WS_BORDER);

            int exStyle = WinAPI.Instance.GetWindowLong(hwnd, GWL_EXSTYLE);
            WinAPI.Instance.SetWindowLong(hwnd, GWL_EXSTYLE, exStyle | WS_EX_WINDOWEDGE);

            WinAPI.Instance.SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE
                            | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
#endif
        }

        public static void SetClientEdge(Control control)
        {
#if !DESIGN

            IntPtr hwnd = control.Handle;
            control.Capture = true;
            hwnd = WinAPI.Instance.GetCapture();
            control.Capture = false;

            int exStyle = WinAPI.Instance.GetWindowLong(hwnd, GWL_EXSTYLE);
            WinAPI.Instance.SetWindowLong(hwnd, GWL_EXSTYLE, exStyle | WS_EX_CLIENTEDGE);
            WinAPI.Instance.SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE
                            | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
#endif
        }       
    }
}
