]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/win32con/win_driver.c
ncurses 6.2 - patch 20200531
[ncurses.git] / ncurses / win32con / win_driver.c
index 78ccfeda1b8289f472ccbf72084121a6919d3e8e..72a9cf53525f8a94d692384347f3b56a552df929 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 1998-2014,2015 Free Software Foundation, Inc.              *
+ * Copyright 2018,2020 Thomas E. Dickey                                     *
+ * Copyright 2008-2016,2017 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -40,7 +41,7 @@
 
 #include <curses.priv.h>
 
-#ifdef __MINGW32__
+#ifdef _WIN32
 #include <tchar.h>
 #else
 #include <windows.h>
 #define PSAPI_VERSION 2
 #include <psapi.h>
 
-#define CUR my_term.type.
+#define CUR TerminalType(my_term).
 
-MODULE_ID("$Id: win_driver.c,v 1.55 2015/02/28 21:30:23 tom Exp $")
+MODULE_ID("$Id: win_driver.c,v 1.66 2020/03/01 00:18:49 tom Exp $")
 
-#ifndef __GNUC__
-#  error We need GCC to compile for MinGW
-#endif
+#define TypeAlloca(type,count) (type*) _alloca(sizeof(type) * (size_t) (count))
 
 #define WINMAGIC NCDRV_MAGIC(NCDRV_WINCONSOLE)
 
@@ -261,7 +260,7 @@ static BOOL
 con_write16(TERMINAL_CONTROL_BLOCK * TCB, int y, int x, cchar_t *str, int limit)
 {
     int actual = 0;
-    CHAR_INFO ci[limit];
+    CHAR_INFO *ci = TypeAlloca(CHAR_INFO, limit);
     COORD loc, siz;
     SMALL_RECT rec;
     int i;
@@ -310,7 +309,7 @@ con_write16(TERMINAL_CONTROL_BLOCK * TCB, int y, int x, cchar_t *str, int limit)
 static BOOL
 con_write8(TERMINAL_CONTROL_BLOCK * TCB, int y, int x, chtype *str, int n)
 {
-    CHAR_INFO ci[n];
+    CHAR_INFO *ci = TypeAlloca(CHAR_INFO, n);
     COORD loc, siz;
     SMALL_RECT rec;
     int i;
@@ -494,7 +493,7 @@ wcon_doupdate(TERMINAL_CONTROL_BLOCK * TCB)
           CurScreen(sp)->_clear,
           NewScreen(sp)->_clear));
 
-       if (SP_PARM->_endwin) {
+       if (SP_PARM->_endwin == ewSuspend) {
 
            T(("coming back from shell mode"));
            NCURSES_SP_NAME(reset_prog_mode) (NCURSES_SP_ARG);
@@ -503,13 +502,13 @@ wcon_doupdate(TERMINAL_CONTROL_BLOCK * TCB)
            NCURSES_SP_NAME(_nc_screen_resume) (NCURSES_SP_ARG);
            SP_PARM->_mouse_resume(SP_PARM);
 
-           SP_PARM->_endwin = FALSE;
+           SP_PARM->_endwin = ewRunning;
        }
 
        if ((CurScreen(sp)->_clear || NewScreen(sp)->_clear)) {
            int x;
 #if USE_WIDEC_SUPPORT
-           cchar_t empty[Width];
+           cchar_t *empty = TypeAlloca(cchar_t, Width);
            wchar_t blank[2] =
            {
                L' ', L'\0'
@@ -518,7 +517,7 @@ wcon_doupdate(TERMINAL_CONTROL_BLOCK * TCB)
            for (x = 0; x < Width; x++)
                setcchar(&empty[x], blank, 0, 0, 0);
 #else
-           chtype empty[Width];
+           chtype *empty = TypeAlloca(chtype, Width);
 
            for (x = 0; x < Width; x++)
                empty[x] = ' ';
@@ -648,8 +647,11 @@ wcon_CanHandle(TERMINAL_CONTROL_BLOCK * TCB,
      * This is intentional, to avoid unnecessary breakage of applications
      * using <term.h> symbols.
      */
-    if (code && (TCB->term.type.Booleans == 0)) {
-       _nc_init_termtype(&(TCB->term.type));
+    if (code && (TerminalType(&TCB->term).Booleans == 0)) {
+       _nc_init_termtype(&TerminalType(&TCB->term));
+#if NCURSES_EXT_NUMBERS
+       _nc_export_termtype2(&TCB->term.type, &TerminalType(&TCB->term));
+#endif
     }
 
     if (!code) {
@@ -671,8 +673,8 @@ wcon_dobeepflash(TERMINAL_CONTROL_BLOCK * TCB,
     int max_cells = (high * wide);
     int i;
 
-    CHAR_INFO this_screen[max_cells];
-    CHAR_INFO that_screen[max_cells];
+    CHAR_INFO *this_screen = TypeAlloca(CHAR_INFO, max_cells);
+    CHAR_INFO *that_screen = TypeAlloca(CHAR_INFO, max_cells);
     COORD this_size;
     SMALL_RECT this_region;
     COORD bufferCoord;
@@ -697,7 +699,9 @@ wcon_dobeepflash(TERMINAL_CONTROL_BLOCK * TCB,
                        bufferCoord,
                        &this_region)) {
 
-           memcpy(that_screen, this_screen, sizeof(that_screen));
+           memcpy(that_screen,
+                  this_screen,
+                  sizeof(CHAR_INFO) * (size_t) max_cells);
 
            for (i = 0; i < max_cells; i++) {
                that_screen[i].Attributes = RevAttr(that_screen[i].Attributes);
@@ -1313,7 +1317,9 @@ wcon_initmouse(TERMINAL_CONTROL_BLOCK * TCB)
 }
 
 static int
-wcon_testmouse(TERMINAL_CONTROL_BLOCK * TCB, int delay)
+wcon_testmouse(TERMINAL_CONTROL_BLOCK * TCB,
+              int delay
+              EVENTLIST_2nd(_nc_eventlist * evl))
 {
     int rc = 0;
     SCREEN *sp;
@@ -1525,6 +1531,10 @@ console_twait(
     int diff;
     bool isImmed = (milliseconds == 0);
 
+#ifdef NCURSES_WGETCH_EVENTS
+    (void) evl;                        /* TODO: implement wgetch-events */
+#endif
+
 #define CONSUME() ReadConsoleInput(fd,&inp_rec,1,&nRead)
 
     assert(sp);
@@ -1632,7 +1642,7 @@ wcon_twait(TERMINAL_CONTROL_BLOCK * TCB,
                             CON.inp,
                             mode,
                             milliseconds,
-                            timeleft EVENTLIST_2nd(_nc_eventlist * evl));
+                            timeleft EVENTLIST_2nd(evl));
     }
     return code;
 }
@@ -1964,7 +1974,7 @@ _nc_mingw_isatty(int fd)
 
 /*   This is used when running in terminfo mode to discover,
      whether or not the "terminal" is actually a Windows
-     Console. It's the responsibilty of the console to deal
+     Console. It's the responsibility of the console to deal
      with the terminal escape sequences that are sent by
      terminfo.
  */
@@ -2066,7 +2076,8 @@ int
 _nc_mingw_testmouse(
                       SCREEN *sp,
                       HANDLE fd,
-                      int delay)
+                      int delay
+                      EVENTLIST_2nd(_nc_eventlist * evl))
 {
     int rc = 0;
 
@@ -2108,7 +2119,7 @@ _nc_mingw_console_read(
        if (b && nRead > 0) {
            if (rc < 0)
                rc = 0;
-           rc += nRead;
+           rc = rc + (int) nRead;
            if (inp_rec.EventType == KEY_EVENT) {
                if (!inp_rec.Event.KeyEvent.bKeyDown)
                    continue;
@@ -2152,7 +2163,7 @@ _nc_mingw_console_read(
 static bool
 InitConsole(void)
 {
-    /* initalize once, or not at all */
+    /* initialize once, or not at all */
     if (!console_initialized) {
        int i;
        DWORD num_buttons;