"""This file includes everything for windows platform"""

import sys
from . import *

if not sys.path[PHardwareITK] == PHardwareITK_P:
    sys.path.append(PHardwareITK_P)

from phardwareitk.Extensions.C import *

from typing import * # type: ignore
import ctypes

# Winuser.h -> Class Styles
CS_BYTEALIGNCLIENT = 0x1000
CS_BYTEALIGNWINDOW = 0x2000
CS_CLASSDC = 0x0040
CS_DBLCLKS = 0x0008
CS_DROPSHADOW = 0x00020000
CS_GLOBALCLASS = 0x4000
CS_HREDRAW = 0x0002
CS_NOCLOSE = 0x0200
CS_OWNDC = 0x0020
CS_PARENTDC = 0x0080
CS_SAVEBITS = 0x0800
CS_VREDRAW = 0x0001

# winuser.h -> Icons
IDI_APPLICATION = 32512
IDI_ERROR = 32513
IDI_QUESTION = 32514
IDI_WARNING = 32515
IDI_INFORMATION = 32516
IDI_WINLOGO = 32517
IDI_SHIELD = 32518

# winuser.h -> Cursors
IDC_ARROW = 32512
IDC_IBEAM = 32513
IDC_WAIT = 32514
IDC_CROSS = 32515
IDC_UPARROW = 32516
IDC_SIZENWSE = 32642
IDC_SIZENESW = 32643
IDC_SIZEWE = 32644
IDC_SIZENS = 32645
IDC_SIZEALL = 32646
IDC_NO = 32648
IDC_HAND = 32649
IDC_APPSTARTING = 32650
IDC_HELP = 32651
IDC_PIN = 32671
IDC_PERSON = 32672

# wingdi -> GetStockObject
# These are copied from win32con (only these ones not others)
WHITE_BRUSH = 0
LTGRAY_BRUSH = 1
GRAY_BRUSH = 2
DKGRAY_BRUSH = 3
BLACK_BRUSH = 4
NULL_BRUSH = 5
HOLLOW_BRUSH = NULL_BRUSH
WHITE_PEN = 6
BLACK_PEN = 7
NULL_PEN = 8
OEM_FIXED_FONT = 10
ANSI_FIXED_FONT = 11
ANSI_VAR_FONT = 12
SYSTEM_FONT = 13
DEVICE_DEFAULT_FONT = 14
DEFAULT_PALETTE = 15

# winuser.h -> Size and location
CW_USEDEFAULT = -2147483648

# winuser.h -> Show Window
SW_HIDE = 0
SW_SHOWNORMAL = 1
SW_NORMAL = 1
SW_SHOWMINIMIZED = 2
SW_SHOWMAXIMIZED = 3
SW_MAXIMIZED = 3
SW_SHOWNOACTIVATE = 4
SW_SHOW = 5
SW_MINIMIZE = 6
SW_SHOWMINNOACTIVE = 7
SW_SHOWNA = 8
SW_RESTORE = 9
SW_SHOWDEFAULT = 10
SW_FORCEMINIMIZE = 11

# wingdi -> Painting and Drawing Messages
WM_DISPLAYCHANGE = 126
WM_ERASEBKGND = 20
WM_NCPAINT = 133
WM_PAINT = 15
WM_PRINT = 791
WM_PRINTCLIENT = 792
WM_SETREDRAW = 11
WM_SYNCPAINT = 136
# Windows Messages
WM_CREATE = 0x0001
WM_DESTROY = 0x0002
WM_CLOSE = 0x0010
WM_SHOWWINDOW = 0x0018
WM_SIZE = 0x0005
WM_MOVE = 0x0003
WM_MOUSEMOVE = 0x0200
WM_LBUTTONDOWN = 0x0201
WM_LBUTTONUP = 0x0202
WM_RBUTTONDOWN = 0x0204
WM_RBUTTONUP = 0x0205
WM_MBUTTONDOWN = 0x0207
WM_MBUTTONUP = 0x0208
WM_MOUSEWHEEL = 0x020A
WM_MOUSELEAVE = 0x02A3
WM_MOUSEHOVER = 0x02A1
WM_KEYDOWN = 0x0100
WM_KEYUP = 0x0101
WM_CHAR = 0x0102
WM_IME_COMPOSITION = 0x010F
WM_IME_ENDCOMPOSITION = 0x010E
WM_DISPLAYCHANGE = 0x007E
WM_POWERBROADCAST = 0x0218
WM_TIMER = 0x0113

# winuser.h -> PeekMessage Constants Part-1
PM_NOREMOVE = 0x0000
PM_REMOVE = 0x0001
PM_NOYIELD = 0x0002

# Windows styles
WS_BORDER = 0x00800000
WS_CAPTION = 0x00C00000
WS_CHILD = 0x40000000
WS_CHILDWINDOW = WS_CHILD
WS_CLIPCHILDREN = 0x02000000
WS_CLIPSIBLINGS = 0x04000000
WS_DISABLED = 0x08000000
WS_DLGFRAME = 0x00400000
WS_GROUP = 0x00020000
WS_HSCROLL = 0x00100000
WS_ICONIC = 0x20000000
WS_MAXIMIZE = 0x01000000
WS_MAXIMIZEBOX = 0x00010000
WS_MINIMIZE = 0x20000000
WS_MINIMIZEBOX = 0x00020000
WS_OVERLAPPED = 0x00000000
WS_SYSMENU = 0x00080000
WS_THICKFRAME = 0x00040000
WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX)
WS_POPUP = 0x80000000
WS_POPUPWINDOW = (WS_POPUP | WS_BORDER | WS_SYSMENU)
WS_SIZEBOX = WS_THICKFRAME
WS_TABSTOP = 0x00010000
WS_TILED = 0x00000000
WS_TILEDWINDOW = (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX)
WS_VISIBLE = 0x10000000
WS_VSCROLL = 0x00200000

# Handle Types
HANDLE = ctypes.c_void_p

HACCEL = HANDLE
HBITMAP = HANDLE
HBRUSH = HANDLE
HCOLORSPACE = HANDLE
HDC = HANDLE
HDESK = HANDLE
HDWP = HANDLE
HENHMETAFILE = HANDLE
HFONT = HANDLE
HGDIOBJ = HANDLE
HGLOBAL = HANDLE
HHOOK = HANDLE
HICON = HANDLE
HCURSOR = HANDLE
HINSTANCE = HANDLE
HKEY = HANDLE
HKL = HANDLE
HLOCAL = HANDLE
HMENU = HANDLE
HMETAFILE = HANDLE
HMODULE = HANDLE
HMONITOR = HANDLE
HPALETTE = HANDLE
HPEN = HANDLE
HRGN = HANDLE
HRSRC = HANDLE
HSTR = HANDLE
HTASK = HANDLE
HWINSTA = HANDLE
HWND = HANDLE
SC_HANDLE = HANDLE
SERVICE_STATUS_HANDLE = HANDLE

# Types
LPCOLESTR = LPOLESTR = OLESTR = ctypes.c_wchar_p
LPCWSTR = LPWSTR = ctypes.c_wchar_p
LPCSTR = LPSTR = ctypes.c_char_p
LPCVOID = LPVOID = ctypes.c_void_p
BYTE = ctypes.c_ubyte
WORD = ctypes.c_ushort
DWORD = ctypes.c_ulong
CHAR = ctypes.c_char
WCHAR = ctypes.c_wchar
UINT = ctypes.c_uint
INT = ctypes.c_int
DOUBLE = ctypes.c_double
FLOAT = ctypes.c_float
BOOLEAN = BYTE
BOOL = ctypes.c_int
ULONG = ctypes.c_ulong
LONG = ctypes.c_long
USHORT = ctypes.c_ushort
SHORT = ctypes.c_short

# Pointer Types
WPARAM  = ctypes.c_uint32
LPARAM  = ctypes.c_int32
LRESULT = ctypes.c_int32

if ctypes.sizeof(ctypes.c_void_p) == 8:
    WPARAM = ctypes.c_uint64
    LPARAM = ctypes.c_int64
    LRESULT = ctypes.c_int64

# Special
WNDPROC = ctypes.WINFUNCTYPE(LRESULT, HWND, UINT, WPARAM, LPARAM)

# Structs
class POINT(ctypes.Structure):
    _fields_ = [("x", LONG), ("y", LONG)]

class MSG(ctypes.Structure):
    _fields_ = [("hWnd", HWND), ("message", UINT), ("wParam", WPARAM), ("lParam", LPARAM), ("time", DWORD), ("pt", POINT)]

    #if ctypes.sizeof(ctypes.c_void_p) == 8: # 64-bit
    #    _fields_.append(("lPrivate", DWORD))

class WNDCLASS(ctypes.Structure):
    _fields_ = [
        ("style", UINT),
        ("lpfnWndProc", WNDPROC),
        ("cbClsExtra", ctypes.c_int),
        ("cbWndExtra", ctypes.c_int),
        ("hInstance", HINSTANCE),
        ("hIcon", HICON),
        ("hCursor", HCURSOR),
        ("hbrBackground", HBRUSH),
        ("lpszMenuName", LPCWSTR),
        ("lpszClassName", LPCWSTR),
    ]