ru.po: Heavily updated translation
[midnight-commander.git] / nt / cons.handler.nt.c
blobe2897532b6e631fc8b7cfef811375480693ee5c1
1 /* Client interface for General purpose Win32 console save/restore server
2 Having the same interface as its Linux counterpart:
3 Copyright (C) 1994 Janne Kukonlehto <jtklehto@stekt.oulu.fi>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 Note:
20 show_console_contents doesn't know how to write to its window
21 the rest works fine.
23 #include <config.h>
24 #ifndef _OS_NT
25 #error This file is for Win32 operating systems.
26 #else
28 #include <windows.h>
29 #include "util.debug.h"
31 int cons_saver_pid = 1;
33 #include "tty.h"
34 #include "util.h"
35 #include "win.h"
36 #include "cons.saver.h"
38 signed char console_flag = 1;
39 static HANDLE hSaved, hNew;
41 void show_console_contents (int starty, unsigned char begin_line, unsigned char end_line)
43 DWORD dw;
44 COORD c0 = { 0, 0 };
45 COORD csize;
46 SMALL_RECT rect;
47 CHAR_INFO *pchar;
49 csize.X = COLS;
50 csize.Y = end_line-begin_line;
51 rect.Left = 0;
52 rect.Top = begin_line;
53 rect.Right = COLS;
54 rect.Bottom = end_line;
56 // -- This code reads characters and attributes
57 pchar = malloc (sizeof(CHAR_INFO) * (end_line-begin_line) * COLS);
58 // Copy from one console to the curses virtual screen
59 win32APICALL(ReadConsoleOutput (hSaved, pchar, csize, c0, &rect));
61 // FIXME: this should've work, but refresh() is called after this write :-(
62 win32APICALL(WriteConsoleOutput (hNew, pchar, csize, c0, &rect));
64 #ifdef USE_NCURSES
65 // Here we read only characters so that we can printw to stdscr.
66 // pchar = malloc (sizeof(TCHAR) * (end_line-begin_line) * COLS);
68 // Copy from one console to the curses virtual screen
69 // ReadConsoleOutputCharacter (hSaved, pchar, (end_line-begin_line) * COLS, c0, &dw);
71 // mvprintw(0, begin_line, "%.*s", (end_line-begin_line) * COLS, pchar);
72 #else
73 //#error show_console_contents not written for S-Lang
74 #endif
77 free (pchar);
80 void handle_console (unsigned char action)
82 static SECURITY_ATTRIBUTES sa;
83 COORD c;
84 CONSOLE_SCREEN_BUFFER_INFO csbi;
85 long lMode;
87 switch (action){
88 case CONSOLE_INIT: // Init
89 hSaved = GetStdHandle (STD_OUTPUT_HANDLE); // Save Standard handle
91 sa.nLength = sizeof(SECURITY_ATTRIBUTES);
92 sa.lpSecurityDescriptor = NULL;
93 sa.bInheritHandle = TRUE; // Create a new console buffer
94 win32APICALL_HANDLE(hNew, /* = */ CreateConsoleScreenBuffer (GENERIC_WRITE | GENERIC_READ,
95 FILE_SHARE_READ | FILE_SHARE_WRITE, &sa,
96 CONSOLE_TEXTMODE_BUFFER, NULL));
97 win32APICALL(GetConsoleScreenBufferInfo(hSaved, &csbi)); // ... with same size
98 win32APICALL(SetConsoleScreenBufferSize(hNew, csbi.dwSize));
100 win32APICALL(SetConsoleActiveScreenBuffer(hNew)); // ... that becomes standard handle
101 win32APICALL(SetConsoleMode(hNew, ENABLE_PROCESSED_INPUT));
102 win32APICALL(SetStdHandle(STD_OUTPUT_HANDLE, hNew));
103 break;
105 case CONSOLE_DONE: // Clean Up
106 win32APICALL(CloseHandle (hNew));
107 break;
109 case CONSOLE_SAVE: // Save
110 win32APICALL(SetConsoleActiveScreenBuffer (hNew)); // Current = our standard handle
111 win32APICALL(SetStdHandle (STD_OUTPUT_HANDLE, hNew));
112 break;
114 case CONSOLE_RESTORE: // Restore
115 win32APICALL(SetConsoleActiveScreenBuffer (hSaved)); // Put saved (shell) screen buffer
116 win32APICALL(SetStdHandle (STD_OUTPUT_HANDLE, hSaved));
117 break;
118 default:
119 win32Trace(("Invalid action code %d received in handle_console", action));
123 #endif // !_OS_NT