// 
// Decompiled by Procyon v0.6.0
// 

package org.jline.terminal.impl.jna.win;

import com.sun.jna.Union;
import java.util.Arrays;
import java.util.List;
import com.sun.jna.Structure;
import com.sun.jna.Native;
import com.sun.jna.win32.W32APIOptions;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.LastErrorException;
import com.sun.jna.Pointer;
import com.sun.jna.win32.StdCallLibrary;

interface Kernel32 extends StdCallLibrary
{
    public static final Kernel32 INSTANCE = (Kernel32)Native.load("kernel32", (Class)Kernel32.class, W32APIOptions.UNICODE_OPTIONS);
    public static final Pointer INVALID_HANDLE_VALUE = Pointer.createConstant(-1L);
    public static final int STD_INPUT_HANDLE = -10;
    public static final int STD_OUTPUT_HANDLE = -11;
    public static final int STD_ERROR_HANDLE = -12;
    public static final int ENABLE_PROCESSED_INPUT = 1;
    public static final int ENABLE_LINE_INPUT = 2;
    public static final int ENABLE_ECHO_INPUT = 4;
    public static final int ENABLE_WINDOW_INPUT = 8;
    public static final int ENABLE_MOUSE_INPUT = 16;
    public static final int ENABLE_INSERT_MODE = 32;
    public static final int ENABLE_QUICK_EDIT_MODE = 64;
    public static final int ENABLE_EXTENDED_FLAGS = 128;
    public static final int RIGHT_ALT_PRESSED = 1;
    public static final int LEFT_ALT_PRESSED = 2;
    public static final int RIGHT_CTRL_PRESSED = 4;
    public static final int LEFT_CTRL_PRESSED = 8;
    public static final int SHIFT_PRESSED = 16;
    public static final int FOREGROUND_BLUE = 1;
    public static final int FOREGROUND_GREEN = 2;
    public static final int FOREGROUND_RED = 4;
    public static final int FOREGROUND_INTENSITY = 8;
    public static final int BACKGROUND_BLUE = 16;
    public static final int BACKGROUND_GREEN = 32;
    public static final int BACKGROUND_RED = 64;
    public static final int BACKGROUND_INTENSITY = 128;
    public static final int FROM_LEFT_1ST_BUTTON_PRESSED = 1;
    public static final int RIGHTMOST_BUTTON_PRESSED = 2;
    public static final int FROM_LEFT_2ND_BUTTON_PRESSED = 4;
    public static final int FROM_LEFT_3RD_BUTTON_PRESSED = 8;
    public static final int FROM_LEFT_4TH_BUTTON_PRESSED = 16;
    public static final int MOUSE_MOVED = 1;
    public static final int DOUBLE_CLICK = 2;
    public static final int MOUSE_WHEELED = 4;
    public static final int MOUSE_HWHEELED = 8;
    
    int WaitForSingleObject(final Pointer p0, final int p1);
    
    Pointer GetStdHandle(final int p0);
    
    void AllocConsole() throws LastErrorException;
    
    void FreeConsole() throws LastErrorException;
    
    Pointer GetConsoleWindow();
    
    int GetConsoleCP();
    
    void FillConsoleOutputCharacter(final Pointer p0, final char p1, final int p2, final COORD p3, final IntByReference p4) throws LastErrorException;
    
    void FillConsoleOutputAttribute(final Pointer p0, final short p1, final int p2, final COORD p3, final IntByReference p4) throws LastErrorException;
    
    void GetConsoleCursorInfo(final Pointer p0, final CONSOLE_CURSOR_INFO.ByReference p1) throws LastErrorException;
    
    void GetConsoleMode(final Pointer p0, final IntByReference p1) throws LastErrorException;
    
    void GetConsoleScreenBufferInfo(final Pointer p0, final CONSOLE_SCREEN_BUFFER_INFO p1) throws LastErrorException;
    
    void GetNumberOfConsoleInputEvents(final Pointer p0, final IntByReference p1) throws LastErrorException;
    
    void ReadConsoleInput(final Pointer p0, final INPUT_RECORD[] p1, final int p2, final IntByReference p3) throws LastErrorException;
    
    void SetConsoleCtrlHandler(final Pointer p0, final boolean p1) throws LastErrorException;
    
    void ReadConsoleOutput(final Pointer p0, final CHAR_INFO[] p1, final COORD p2, final COORD p3, final SMALL_RECT p4) throws LastErrorException;
    
    void ReadConsoleOutputA(final Pointer p0, final CHAR_INFO[] p1, final COORD p2, final COORD p3, final SMALL_RECT p4) throws LastErrorException;
    
    void ReadConsoleOutputCharacter(final Pointer p0, final char[] p1, final int p2, final COORD p3, final IntByReference p4) throws LastErrorException;
    
    void ReadConsoleOutputCharacterA(final Pointer p0, final byte[] p1, final int p2, final COORD p3, final IntByReference p4) throws LastErrorException;
    
    void SetConsoleCursorInfo(final Pointer p0, final CONSOLE_CURSOR_INFO p1) throws LastErrorException;
    
    void SetConsoleCP(final int p0) throws LastErrorException;
    
    void SetConsoleOutputCP(final int p0) throws LastErrorException;
    
    void SetConsoleCursorPosition(final Pointer p0, final COORD p1) throws LastErrorException;
    
    void SetConsoleMode(final Pointer p0, final int p1) throws LastErrorException;
    
    void SetConsoleScreenBufferSize(final Pointer p0, final COORD p1) throws LastErrorException;
    
    void SetConsoleTextAttribute(final Pointer p0, final short p1) throws LastErrorException;
    
    void SetConsoleTitle(final String p0) throws LastErrorException;
    
    void SetConsoleWindowInfo(final Pointer p0, final boolean p1, final SMALL_RECT p2) throws LastErrorException;
    
    void WriteConsoleW(final Pointer p0, final char[] p1, final int p2, final IntByReference p3, final Pointer p4) throws LastErrorException;
    
    void WriteConsoleOutput(final Pointer p0, final CHAR_INFO[] p1, final COORD p2, final COORD p3, final SMALL_RECT p4) throws LastErrorException;
    
    void WriteConsoleOutputA(final Pointer p0, final CHAR_INFO[] p1, final COORD p2, final COORD p3, final SMALL_RECT p4) throws LastErrorException;
    
    void WriteConsoleOutputCharacter(final Pointer p0, final char[] p1, final int p2, final COORD p3, final IntByReference p4) throws LastErrorException;
    
    void WriteConsoleOutputCharacterA(final Pointer p0, final byte[] p1, final int p2, final COORD p3, final IntByReference p4) throws LastErrorException;
    
    void ScrollConsoleScreenBuffer(final Pointer p0, final SMALL_RECT p1, final SMALL_RECT p2, final COORD p3, final CHAR_INFO p4) throws LastErrorException;
    
    public static class CHAR_INFO extends Structure
    {
        public UnionChar uChar;
        public short Attributes;
        private static String[] fieldOrder;
        
        public CHAR_INFO() {
        }
        
        public CHAR_INFO(final char c, final short attr) {
            this.uChar = new UnionChar(c);
            this.Attributes = attr;
        }
        
        public CHAR_INFO(final byte c, final short attr) {
            this.uChar = new UnionChar(c);
            this.Attributes = attr;
        }
        
        public static CHAR_INFO[] createArray(final int size) {
            return (CHAR_INFO[])new CHAR_INFO().toArray(size);
        }
        
        protected List<String> getFieldOrder() {
            return Arrays.asList(CHAR_INFO.fieldOrder);
        }
        
        static {
            CHAR_INFO.fieldOrder = new String[] { "uChar", "Attributes" };
        }
    }
    
    public static class CONSOLE_CURSOR_INFO extends Structure
    {
        public int dwSize;
        public boolean bVisible;
        private static String[] fieldOrder;
        
        protected List<String> getFieldOrder() {
            return Arrays.asList(CONSOLE_CURSOR_INFO.fieldOrder);
        }
        
        static {
            CONSOLE_CURSOR_INFO.fieldOrder = new String[] { "dwSize", "bVisible" };
        }
        
        public static class ByReference extends CONSOLE_CURSOR_INFO implements Structure.ByReference
        {
        }
    }
    
    public static class CONSOLE_SCREEN_BUFFER_INFO extends Structure
    {
        public COORD dwSize;
        public COORD dwCursorPosition;
        public short wAttributes;
        public SMALL_RECT srWindow;
        public COORD dwMaximumWindowSize;
        private static String[] fieldOrder;
        
        protected List<String> getFieldOrder() {
            return Arrays.asList(CONSOLE_SCREEN_BUFFER_INFO.fieldOrder);
        }
        
        public int windowWidth() {
            return this.srWindow.width() + 1;
        }
        
        public int windowHeight() {
            return this.srWindow.height() + 1;
        }
        
        static {
            CONSOLE_SCREEN_BUFFER_INFO.fieldOrder = new String[] { "dwSize", "dwCursorPosition", "wAttributes", "srWindow", "dwMaximumWindowSize" };
        }
    }
    
    public static class COORD extends Structure implements Structure.ByValue
    {
        public short X;
        public short Y;
        private static String[] fieldOrder;
        
        public COORD() {
        }
        
        public COORD(final short X, final short Y) {
            this.X = X;
            this.Y = Y;
        }
        
        protected List<String> getFieldOrder() {
            return Arrays.asList(COORD.fieldOrder);
        }
        
        static {
            COORD.fieldOrder = new String[] { "X", "Y" };
        }
    }
    
    public static class INPUT_RECORD extends Structure
    {
        public static final short KEY_EVENT = 1;
        public static final short MOUSE_EVENT = 2;
        public static final short WINDOW_BUFFER_SIZE_EVENT = 4;
        public static final short MENU_EVENT = 8;
        public static final short FOCUS_EVENT = 16;
        public short EventType;
        public EventUnion Event;
        private static String[] fieldOrder;
        
        public void read() {
            this.readField("EventType");
            switch (this.EventType) {
                case 1: {
                    this.Event.setType((Class)KEY_EVENT_RECORD.class);
                    break;
                }
                case 2: {
                    this.Event.setType((Class)MOUSE_EVENT_RECORD.class);
                    break;
                }
                case 4: {
                    this.Event.setType((Class)WINDOW_BUFFER_SIZE_RECORD.class);
                    break;
                }
                case 8: {
                    this.Event.setType((Class)MENU_EVENT_RECORD.class);
                    break;
                }
                case 16: {
                    this.Event.setType((Class)MENU_EVENT_RECORD.class);
                    break;
                }
            }
            super.read();
        }
        
        protected List<String> getFieldOrder() {
            return Arrays.asList(INPUT_RECORD.fieldOrder);
        }
        
        static {
            INPUT_RECORD.fieldOrder = new String[] { "EventType", "Event" };
        }
        
        public static class EventUnion extends Union
        {
            public KEY_EVENT_RECORD KeyEvent;
            public MOUSE_EVENT_RECORD MouseEvent;
            public WINDOW_BUFFER_SIZE_RECORD WindowBufferSizeEvent;
            public MENU_EVENT_RECORD MenuEvent;
            public FOCUS_EVENT_RECORD FocusEvent;
        }
    }
    
    public static class KEY_EVENT_RECORD extends Structure
    {
        public boolean bKeyDown;
        public short wRepeatCount;
        public short wVirtualKeyCode;
        public short wVirtualScanCode;
        public UnionChar uChar;
        public int dwControlKeyState;
        private static String[] fieldOrder;
        
        protected List<String> getFieldOrder() {
            return Arrays.asList(KEY_EVENT_RECORD.fieldOrder);
        }
        
        static {
            KEY_EVENT_RECORD.fieldOrder = new String[] { "bKeyDown", "wRepeatCount", "wVirtualKeyCode", "wVirtualScanCode", "uChar", "dwControlKeyState" };
        }
    }
    
    public static class MOUSE_EVENT_RECORD extends Structure
    {
        public COORD dwMousePosition;
        public int dwButtonState;
        public int dwControlKeyState;
        public int dwEventFlags;
        private static String[] fieldOrder;
        
        protected List<String> getFieldOrder() {
            return Arrays.asList(MOUSE_EVENT_RECORD.fieldOrder);
        }
        
        static {
            MOUSE_EVENT_RECORD.fieldOrder = new String[] { "dwMousePosition", "dwButtonState", "dwControlKeyState", "dwEventFlags" };
        }
    }
    
    public static class WINDOW_BUFFER_SIZE_RECORD extends Structure
    {
        public COORD dwSize;
        private static String[] fieldOrder;
        
        protected List<String> getFieldOrder() {
            return Arrays.asList(WINDOW_BUFFER_SIZE_RECORD.fieldOrder);
        }
        
        static {
            WINDOW_BUFFER_SIZE_RECORD.fieldOrder = new String[] { "dwSize" };
        }
    }
    
    public static class MENU_EVENT_RECORD extends Structure
    {
        public int dwCommandId;
        private static String[] fieldOrder;
        
        protected List<String> getFieldOrder() {
            return Arrays.asList(MENU_EVENT_RECORD.fieldOrder);
        }
        
        static {
            MENU_EVENT_RECORD.fieldOrder = new String[] { "dwCommandId" };
        }
    }
    
    public static class FOCUS_EVENT_RECORD extends Structure
    {
        public boolean bSetFocus;
        private static String[] fieldOrder;
        
        protected List<String> getFieldOrder() {
            return Arrays.asList(FOCUS_EVENT_RECORD.fieldOrder);
        }
        
        static {
            FOCUS_EVENT_RECORD.fieldOrder = new String[] { "bSetFocus" };
        }
    }
    
    public static class SMALL_RECT extends Structure
    {
        public short Left;
        public short Top;
        public short Right;
        public short Bottom;
        private static String[] fieldOrder;
        
        public SMALL_RECT() {
        }
        
        public SMALL_RECT(final SMALL_RECT org) {
            this(org.Top, org.Left, org.Bottom, org.Right);
        }
        
        public SMALL_RECT(final short Top, final short Left, final short Bottom, final short Right) {
            this.Top = Top;
            this.Left = Left;
            this.Bottom = Bottom;
            this.Right = Right;
        }
        
        protected List<String> getFieldOrder() {
            return Arrays.asList(SMALL_RECT.fieldOrder);
        }
        
        public short width() {
            return (short)(this.Right - this.Left);
        }
        
        public short height() {
            return (short)(this.Bottom - this.Top);
        }
        
        static {
            SMALL_RECT.fieldOrder = new String[] { "Left", "Top", "Right", "Bottom" };
        }
    }
    
    public static class UnionChar extends Union
    {
        public char UnicodeChar;
        public byte AsciiChar;
        
        public UnionChar() {
        }
        
        public UnionChar(final char c) {
            this.setType((Class)Character.TYPE);
            this.UnicodeChar = c;
        }
        
        public UnionChar(final byte c) {
            this.setType((Class)Byte.TYPE);
            this.AsciiChar = c;
        }
        
        public void set(final char c) {
            this.setType((Class)Character.TYPE);
            this.UnicodeChar = c;
        }
        
        public void set(final byte c) {
            this.setType((Class)Byte.TYPE);
            this.AsciiChar = c;
        }
    }
}
