module win32.ansi.wincon;

// Translated from Microsoft Platform SDK August 2001 Edition
// by Y.Tomino (demoonlit@inter7.jp)

import win32.ansi.winbase;

// #ifndef _WINCON_
// #define _WINCON_

// #ifdef __cplusplus
// extern "C" {
// #endif

struct _COORD {
  SHORT X;
  SHORT Y;
}
alias _COORD COORD;
alias _COORD* PCOORD;

struct _SMALL_RECT {
  SHORT Left;
  SHORT Top;
  SHORT Right;
  SHORT Bottom;
}
alias _SMALL_RECT SMALL_RECT;
alias _SMALL_RECT* PSMALL_RECT;

struct _KEY_EVENT_RECORD {
  BOOL bKeyDown;
  WORD wRepeatCount;
  WORD wVirtualKeyCode;
  WORD wVirtualScanCode;
union {
  WCHAR UnicodeChar;
  CHAR AsciiChar;
}

  DWORD dwControlKeyState;
}
alias _KEY_EVENT_RECORD KEY_EVENT_RECORD;
alias _KEY_EVENT_RECORD* PKEY_EVENT_RECORD;

enum : uint { RIGHT_ALT_PRESSED = 0x0001 }
enum : uint { LEFT_ALT_PRESSED = 0x0002 }
enum : uint { RIGHT_CTRL_PRESSED = 0x0004 }
enum : uint { LEFT_CTRL_PRESSED = 0x0008 }
enum : uint { SHIFT_PRESSED = 0x0010 }
enum : uint { NUMLOCK_ON = 0x0020 }
enum : uint { SCROLLLOCK_ON = 0x0040 }
enum : uint { CAPSLOCK_ON = 0x0080 }
enum : uint { ENHANCED_KEY = 0x0100 }
enum : uint { NLS_DBCSCHAR = 0x00010000 }
enum : uint { NLS_ALPHANUMERIC = 0x00000000 }
enum : uint { NLS_KATAKANA = 0x00020000 }
enum : uint { NLS_HIRAGANA = 0x00040000 }
enum : uint { NLS_ROMAN = 0x00400000 }
enum : uint { NLS_IME_CONVERSION = 0x00800000 }
enum : uint { NLS_IME_DISABLE = 0x20000000 }

struct _MOUSE_EVENT_RECORD {
  COORD dwMousePosition;
  DWORD dwButtonState;
  DWORD dwControlKeyState;
  DWORD dwEventFlags;
}
alias _MOUSE_EVENT_RECORD MOUSE_EVENT_RECORD;
alias _MOUSE_EVENT_RECORD* PMOUSE_EVENT_RECORD;

enum : uint { FROM_LEFT_1ST_BUTTON_PRESSED = 0x0001 }
enum : uint { RIGHTMOST_BUTTON_PRESSED = 0x0002 }
enum : uint { FROM_LEFT_2ND_BUTTON_PRESSED = 0x0004 }
enum : uint { FROM_LEFT_3RD_BUTTON_PRESSED = 0x0008 }
enum : uint { FROM_LEFT_4TH_BUTTON_PRESSED = 0x0010 }

enum : uint { MOUSE_MOVED = 0x0001 }
enum : uint { DOUBLE_CLICK = 0x0002 }
enum : uint { MOUSE_WHEELED = 0x0004 }

struct _WINDOW_BUFFER_SIZE_RECORD {
  COORD dwSize;
}
alias _WINDOW_BUFFER_SIZE_RECORD WINDOW_BUFFER_SIZE_RECORD;
alias _WINDOW_BUFFER_SIZE_RECORD* PWINDOW_BUFFER_SIZE_RECORD;

struct _MENU_EVENT_RECORD {
  UINT dwCommandId;
}
alias _MENU_EVENT_RECORD MENU_EVENT_RECORD;
alias _MENU_EVENT_RECORD* PMENU_EVENT_RECORD;

struct _FOCUS_EVENT_RECORD {
  BOOL bSetFocus;
}
alias _FOCUS_EVENT_RECORD FOCUS_EVENT_RECORD;
alias _FOCUS_EVENT_RECORD* PFOCUS_EVENT_RECORD;

struct _INPUT_RECORD {
  WORD EventType;
union {
  KEY_EVENT_RECORD KeyEvent;
  MOUSE_EVENT_RECORD MouseEvent;
  WINDOW_BUFFER_SIZE_RECORD WindowBufferSizeEvent;
  MENU_EVENT_RECORD MenuEvent;
  FOCUS_EVENT_RECORD FocusEvent;
}

}
alias _INPUT_RECORD INPUT_RECORD;
alias _INPUT_RECORD* PINPUT_RECORD;

enum : uint { KEY_EVENT = 0x0001 }
enum : uint { MOUSE_EVENT = 0x0002 }
enum : uint { WINDOW_BUFFER_SIZE_EVENT = 0x0004 }
enum : uint { MENU_EVENT = 0x0008 }
enum : uint { FOCUS_EVENT = 0x0010 }

struct _CHAR_INFO {
union {
  WCHAR UnicodeChar;
  CHAR AsciiChar;
}

  WORD Attributes;
}
alias _CHAR_INFO CHAR_INFO;
alias _CHAR_INFO* PCHAR_INFO;

enum : uint { FOREGROUND_BLUE = 0x0001 }
enum : uint { FOREGROUND_GREEN = 0x0002 }
enum : uint { FOREGROUND_RED = 0x0004 }
enum : uint { FOREGROUND_INTENSITY = 0x0008 }
enum : uint { BACKGROUND_BLUE = 0x0010 }
enum : uint { BACKGROUND_GREEN = 0x0020 }
enum : uint { BACKGROUND_RED = 0x0040 }
enum : uint { BACKGROUND_INTENSITY = 0x0080 }
enum : uint { COMMON_LVB_LEADING_BYTE = 0x0100 }
enum : uint { COMMON_LVB_TRAILING_BYTE = 0x0200 }
enum : uint { COMMON_LVB_GRID_HORIZONTAL = 0x0400 }
enum : uint { COMMON_LVB_GRID_LVERTICAL = 0x0800 }
enum : uint { COMMON_LVB_GRID_RVERTICAL = 0x1000 }
enum : uint { COMMON_LVB_REVERSE_VIDEO = 0x4000 }
enum : uint { COMMON_LVB_UNDERSCORE = 0x8000 }

enum : uint { COMMON_LVB_SBCSDBCS = 0x0300 }

struct _CONSOLE_SCREEN_BUFFER_INFO {
  COORD dwSize;
  COORD dwCursorPosition;
  WORD wAttributes;
  SMALL_RECT srWindow;
  COORD dwMaximumWindowSize;
}
alias _CONSOLE_SCREEN_BUFFER_INFO CONSOLE_SCREEN_BUFFER_INFO;
alias _CONSOLE_SCREEN_BUFFER_INFO* PCONSOLE_SCREEN_BUFFER_INFO;

struct _CONSOLE_CURSOR_INFO {
  DWORD dwSize;
  BOOL bVisible;
}
alias _CONSOLE_CURSOR_INFO CONSOLE_CURSOR_INFO;
alias _CONSOLE_CURSOR_INFO* PCONSOLE_CURSOR_INFO;

struct _CONSOLE_FONT_INFO {
  DWORD nFont;
  COORD dwFontSize;
}
alias _CONSOLE_FONT_INFO CONSOLE_FONT_INFO;
alias _CONSOLE_FONT_INFO* PCONSOLE_FONT_INFO;

// #if(_WIN32_WINNT >= 0x0500)
struct _CONSOLE_SELECTION_INFO {
  DWORD dwFlags;
  COORD dwSelectionAnchor;
  SMALL_RECT srSelection;
}
alias _CONSOLE_SELECTION_INFO CONSOLE_SELECTION_INFO;
alias _CONSOLE_SELECTION_INFO* PCONSOLE_SELECTION_INFO;

enum : uint { CONSOLE_NO_SELECTION = 0x0000 }
enum : uint { CONSOLE_SELECTION_IN_PROGRESS = 0x0001 }
enum : uint { CONSOLE_SELECTION_NOT_EMPTY = 0x0002 }
enum : uint { CONSOLE_MOUSE_SELECTION = 0x0004 }
enum : uint { CONSOLE_MOUSE_DOWN = 0x0008 }
// #endif /* _WIN32_WINNT >= 0x0500 */

extern(Windows) alias BOOL function( DWORD CtrlType ) PHANDLER_ROUTINE;

enum : uint { CTRL_C_EVENT = 0 }
enum : uint { CTRL_BREAK_EVENT = 1 }
enum : uint { CTRL_CLOSE_EVENT = 2 }

enum : uint { CTRL_LOGOFF_EVENT = 5 }
enum : uint { CTRL_SHUTDOWN_EVENT = 6 }

enum : uint { ENABLE_PROCESSED_INPUT = 0x0001 }
enum : uint { ENABLE_LINE_INPUT = 0x0002 }
enum : uint { ENABLE_ECHO_INPUT = 0x0004 }
enum : uint { ENABLE_WINDOW_INPUT = 0x0008 }
enum : uint { ENABLE_MOUSE_INPUT = 0x0010 }

enum : uint { ENABLE_PROCESSED_OUTPUT = 0x0001 }
enum : uint { ENABLE_WRAP_AT_EOL_OUTPUT = 0x0002 }

extern(Windows) export BOOL PeekConsoleInputA(
  HANDLE hConsoleInput,
  PINPUT_RECORD lpBuffer,
  DWORD nLength,
  LPDWORD lpNumberOfEventsRead);
extern(Windows) export BOOL PeekConsoleInputW(
  HANDLE hConsoleInput,
  PINPUT_RECORD lpBuffer,
  DWORD nLength,
  LPDWORD lpNumberOfEventsRead);
// #ifdef UNICODE
// #...
// #else
alias PeekConsoleInputA PeekConsoleInput;
// #endif // !UNICODE

extern(Windows) export BOOL ReadConsoleInputA(
  HANDLE hConsoleInput,
  PINPUT_RECORD lpBuffer,
  DWORD nLength,
  LPDWORD lpNumberOfEventsRead);
extern(Windows) export BOOL ReadConsoleInputW(
  HANDLE hConsoleInput,
  PINPUT_RECORD lpBuffer,
  DWORD nLength,
  LPDWORD lpNumberOfEventsRead);
// #ifdef UNICODE
// #...
// #else
alias ReadConsoleInputA ReadConsoleInput;
// #endif // !UNICODE

extern(Windows) export BOOL WriteConsoleInputA(
  HANDLE hConsoleInput,
  INPUT_RECORD *lpBuffer,
  DWORD nLength,
  LPDWORD lpNumberOfEventsWritten);
extern(Windows) export BOOL WriteConsoleInputW(
  HANDLE hConsoleInput,
  INPUT_RECORD *lpBuffer,
  DWORD nLength,
  LPDWORD lpNumberOfEventsWritten);
// #ifdef UNICODE
// #...
// #else
alias WriteConsoleInputA WriteConsoleInput;
// #endif // !UNICODE

extern(Windows) export BOOL ReadConsoleOutputA(
  HANDLE hConsoleOutput,
  PCHAR_INFO lpBuffer,
  COORD dwBufferSize,
  COORD dwBufferCoord,
  PSMALL_RECT lpReadRegion);
extern(Windows) export BOOL ReadConsoleOutputW(
  HANDLE hConsoleOutput,
  PCHAR_INFO lpBuffer,
  COORD dwBufferSize,
  COORD dwBufferCoord,
  PSMALL_RECT lpReadRegion);
// #ifdef UNICODE
// #...
// #else
alias ReadConsoleOutputA ReadConsoleOutput;
// #endif // !UNICODE

extern(Windows) export BOOL WriteConsoleOutputA(
  HANDLE hConsoleOutput,
  CHAR_INFO *lpBuffer,
  COORD dwBufferSize,
  COORD dwBufferCoord,
  PSMALL_RECT lpWriteRegion);
extern(Windows) export BOOL WriteConsoleOutputW(
  HANDLE hConsoleOutput,
  CHAR_INFO *lpBuffer,
  COORD dwBufferSize,
  COORD dwBufferCoord,
  PSMALL_RECT lpWriteRegion);
// #ifdef UNICODE
// #...
// #else
alias WriteConsoleOutputA WriteConsoleOutput;
// #endif // !UNICODE

extern(Windows) export BOOL ReadConsoleOutputCharacterA(
  HANDLE hConsoleOutput,
  LPSTR lpCharacter,
  DWORD nLength,
  COORD dwReadCoord,
  LPDWORD lpNumberOfCharsRead);
extern(Windows) export BOOL ReadConsoleOutputCharacterW(
  HANDLE hConsoleOutput,
  LPWSTR lpCharacter,
  DWORD nLength,
  COORD dwReadCoord,
  LPDWORD lpNumberOfCharsRead);
// #ifdef UNICODE
// #...
// #else
alias ReadConsoleOutputCharacterA ReadConsoleOutputCharacter;
// #endif // !UNICODE

extern(Windows) export BOOL ReadConsoleOutputAttribute(
  HANDLE hConsoleOutput,
  LPWORD lpAttribute,
  DWORD nLength,
  COORD dwReadCoord,
  LPDWORD lpNumberOfAttrsRead);

extern(Windows) export BOOL WriteConsoleOutputCharacterA(
  HANDLE hConsoleOutput,
  LPCSTR lpCharacter,
  DWORD nLength,
  COORD dwWriteCoord,
  LPDWORD lpNumberOfCharsWritten);
extern(Windows) export BOOL WriteConsoleOutputCharacterW(
  HANDLE hConsoleOutput,
  LPCWSTR lpCharacter,
  DWORD nLength,
  COORD dwWriteCoord,
  LPDWORD lpNumberOfCharsWritten);
// #ifdef UNICODE
// #...
// #else
alias WriteConsoleOutputCharacterA WriteConsoleOutputCharacter;
// #endif // !UNICODE

extern(Windows) export BOOL WriteConsoleOutputAttribute(
  HANDLE hConsoleOutput,
  WORD *lpAttribute,
  DWORD nLength,
  COORD dwWriteCoord,
  LPDWORD lpNumberOfAttrsWritten);

extern(Windows) export BOOL FillConsoleOutputCharacterA(
  HANDLE hConsoleOutput,
  CHAR cCharacter,
  DWORD nLength,
  COORD dwWriteCoord,
  LPDWORD lpNumberOfCharsWritten);
extern(Windows) export BOOL FillConsoleOutputCharacterW(
  HANDLE hConsoleOutput,
  WCHAR cCharacter,
  DWORD nLength,
  COORD dwWriteCoord,
  LPDWORD lpNumberOfCharsWritten);
// #ifdef UNICODE
// #...
// #else
alias FillConsoleOutputCharacterA FillConsoleOutputCharacter;
// #endif // !UNICODE

extern(Windows) export BOOL FillConsoleOutputAttribute(
  HANDLE hConsoleOutput,
  WORD wAttribute,
  DWORD nLength,
  COORD dwWriteCoord,
  LPDWORD lpNumberOfAttrsWritten);

extern(Windows) export BOOL GetConsoleMode(
  HANDLE hConsoleHandle,
  LPDWORD lpMode);

extern(Windows) export BOOL GetNumberOfConsoleInputEvents(
  HANDLE hConsoleInput,
  LPDWORD lpNumberOfEvents);

extern(Windows) export BOOL GetConsoleScreenBufferInfo(
  HANDLE hConsoleOutput,
  PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo);

extern(Windows) export COORD GetLargestConsoleWindowSize(
  HANDLE hConsoleOutput);

extern(Windows) export BOOL GetConsoleCursorInfo(
  HANDLE hConsoleOutput,
  PCONSOLE_CURSOR_INFO lpConsoleCursorInfo);

// #if(_WIN32_WINNT >= 0x0500)

extern(Windows) export BOOL GetCurrentConsoleFont(
  HANDLE hConsoleOutput,
  BOOL bMaximumWindow,
  PCONSOLE_FONT_INFO lpConsoleCurrentFont);

extern(Windows) export COORD GetConsoleFontSize(
  HANDLE hConsoleOutput,
  DWORD nFont);

extern(Windows) export BOOL GetConsoleSelectionInfo(
  PCONSOLE_SELECTION_INFO lpConsoleSelectionInfo);

// #endif /* _WIN32_WINNT >= 0x0500 */

extern(Windows) export BOOL GetNumberOfConsoleMouseButtons(
  LPDWORD lpNumberOfMouseButtons);

extern(Windows) export BOOL SetConsoleMode(
  HANDLE hConsoleHandle,
  DWORD dwMode);

extern(Windows) export BOOL SetConsoleActiveScreenBuffer(
  HANDLE hConsoleOutput);

extern(Windows) export BOOL FlushConsoleInputBuffer(
  HANDLE hConsoleInput);

extern(Windows) export BOOL SetConsoleScreenBufferSize(
  HANDLE hConsoleOutput,
  COORD dwSize);

extern(Windows) export BOOL SetConsoleCursorPosition(
  HANDLE hConsoleOutput,
  COORD dwCursorPosition);

extern(Windows) export BOOL SetConsoleCursorInfo(
  HANDLE hConsoleOutput,
  CONSOLE_CURSOR_INFO *lpConsoleCursorInfo);

extern(Windows) export BOOL ScrollConsoleScreenBufferA(
  HANDLE hConsoleOutput,
  SMALL_RECT *lpScrollRectangle,
  SMALL_RECT *lpClipRectangle,
  COORD dwDestinationOrigin,
  CHAR_INFO *lpFill);
extern(Windows) export BOOL ScrollConsoleScreenBufferW(
  HANDLE hConsoleOutput,
  SMALL_RECT *lpScrollRectangle,
  SMALL_RECT *lpClipRectangle,
  COORD dwDestinationOrigin,
  CHAR_INFO *lpFill);
// #ifdef UNICODE
// #...
// #else
alias ScrollConsoleScreenBufferA ScrollConsoleScreenBuffer;
// #endif // !UNICODE

extern(Windows) export BOOL SetConsoleWindowInfo(
  HANDLE hConsoleOutput,
  BOOL bAbsolute,
  SMALL_RECT *lpConsoleWindow);

extern(Windows) export BOOL SetConsoleTextAttribute(
  HANDLE hConsoleOutput,
  WORD wAttributes);

extern(Windows) export BOOL SetConsoleCtrlHandler(
  PHANDLER_ROUTINE HandlerRoutine,
  BOOL Add);

extern(Windows) export BOOL GenerateConsoleCtrlEvent(
  DWORD dwCtrlEvent,
  DWORD dwProcessGroupId);

extern(Windows) export BOOL AllocConsole();

extern(Windows) export BOOL FreeConsole();

// #if(_WIN32_WINNT >= 0x0500)
extern(Windows) export BOOL AttachConsole(
  DWORD dwProcessId);
// #endif /* _WIN32_WINNT >= 0x0500 */

extern(Windows) export DWORD GetConsoleTitleA(
  LPSTR lpConsoleTitle,
  DWORD nSize);
extern(Windows) export DWORD GetConsoleTitleW(
  LPWSTR lpConsoleTitle,
  DWORD nSize);
// #ifdef UNICODE
// #...
// #else
alias GetConsoleTitleA GetConsoleTitle;
// #endif // !UNICODE

extern(Windows) export BOOL SetConsoleTitleA(
  LPCSTR lpConsoleTitle);
extern(Windows) export BOOL SetConsoleTitleW(
  LPCWSTR lpConsoleTitle);
// #ifdef UNICODE
// #...
// #else
alias SetConsoleTitleA SetConsoleTitle;
// #endif // !UNICODE

extern(Windows) export BOOL ReadConsoleA(
  HANDLE hConsoleInput,
  LPVOID lpBuffer,
  DWORD nNumberOfCharsToRead,
  LPDWORD lpNumberOfCharsRead,
  LPVOID lpReserved);
extern(Windows) export BOOL ReadConsoleW(
  HANDLE hConsoleInput,
  LPVOID lpBuffer,
  DWORD nNumberOfCharsToRead,
  LPDWORD lpNumberOfCharsRead,
  LPVOID lpReserved);
// #ifdef UNICODE
// #...
// #else
alias ReadConsoleA ReadConsole;
// #endif // !UNICODE

extern(Windows) export BOOL WriteConsoleA(
  HANDLE hConsoleOutput,
  VOID *lpBuffer,
  DWORD nNumberOfCharsToWrite,
  LPDWORD lpNumberOfCharsWritten,
  LPVOID lpReserved);
extern(Windows) export BOOL WriteConsoleW(
  HANDLE hConsoleOutput,
  VOID *lpBuffer,
  DWORD nNumberOfCharsToWrite,
  LPDWORD lpNumberOfCharsWritten,
  LPVOID lpReserved);
// #ifdef UNICODE
// #...
// #else
alias WriteConsoleA WriteConsole;
// #endif // !UNICODE

enum : uint { CONSOLE_TEXTMODE_BUFFER = 1 }

extern(Windows) export HANDLE CreateConsoleScreenBuffer(
  DWORD dwDesiredAccess,
  DWORD dwShareMode,
  SECURITY_ATTRIBUTES *lpSecurityAttributes,
  DWORD dwFlags,
  LPVOID lpScreenBufferData);

extern(Windows) export UINT GetConsoleCP();

extern(Windows) export BOOL SetConsoleCP(
  UINT wCodePageID);

extern(Windows) export UINT GetConsoleOutputCP();

extern(Windows) export BOOL SetConsoleOutputCP(
  UINT wCodePageID);

// #if(_WIN32_WINNT >= 0x0500)

enum : uint { CONSOLE_FULLSCREEN = 1 }
enum : uint { CONSOLE_FULLSCREEN_HARDWARE = 2 }

extern(Windows) export BOOL GetConsoleDisplayMode(
  LPDWORD lpModeFlags);

extern(Windows) export HWND GetConsoleWindow();

// #endif /* _WIN32_WINNT >= 0x0500 */

// #if(_WIN32_WINNT >= 0x0501)

extern(Windows) export DWORD GetConsoleProcessList(
  LPDWORD lpdwProcessList,
  DWORD dwProcessCount);
// #endif /* _WIN32_WINNT >= 0x0501 */

// #ifdef __cplusplus
// }
// #endif

// #endif // _WINCON_

