Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygentmouse.cpp
Go to the documentation of this file.
00001 00002 //Telnet Win32 : an ANSI telnet client. 00003 //Copyright (C) 1998 Paul Brannan 00004 //Copyright (C) 1998 I.Ioannou 00005 //Copyright (C) 1997 Brad Johnson 00006 // 00007 //This program is free software; you can redistribute it and/or 00008 //modify it under the terms of the GNU General Public License 00009 //as published by the Free Software Foundation; either version 2 00010 //of the License, or (at your option) any later version. 00011 // 00012 //This program is distributed in the hope that it will be useful, 00013 //but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 //GNU General Public License for more details. 00016 // 00017 //You should have received a copy of the GNU General Public License 00018 //along with this program; if not, write to the Free Software 00019 //Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00020 // 00021 //I.Ioannou 00022 //roryt@hol.gr 00023 // 00025 00026 // TMouse.cpp 00027 // A simple class for handling mouse events 00028 // Written by Paul Brannan <pbranna@clemson.edu> 00029 // Last modified August 30, 1998 00030 00031 #include "precomp.h" 00032 00033 TMouse::TMouse(Tnclip &RefClipboard): Clipboard(RefClipboard) { 00034 hConsole = GetStdHandle(STD_INPUT_HANDLE); 00035 hStdout = GetStdHandle(STD_OUTPUT_HANDLE); 00036 } 00037 00038 TMouse::~TMouse() { 00039 } 00040 00041 void TMouse::get_coords(COORD *start_coords, COORD *end_coords, 00042 COORD *first_coords, COORD *last_coords) { 00043 if(end_coords->Y < start_coords->Y || 00044 (end_coords->Y == start_coords->Y && end_coords->X < start_coords->X)) 00045 { 00046 *first_coords = *end_coords; 00047 *last_coords = *start_coords; 00048 } else { 00049 *first_coords = *start_coords; 00050 *last_coords = *end_coords; 00051 } 00052 last_coords->X++; 00053 } 00054 00055 void TMouse::doMouse_init() { 00056 GetConsoleScreenBufferInfo(hStdout, &ConsoleInfo); 00057 chiBuffer = newBuffer(); 00058 saveScreen(chiBuffer); 00059 } 00060 00061 void TMouse::doMouse_cleanup() { 00062 restoreScreen(chiBuffer); 00063 delete[] chiBuffer; 00064 } 00065 00066 void TMouse::move_mouse(COORD start_coords, COORD end_coords) { 00067 COORD screen_start = {0, 0}; 00068 COORD first_coords, last_coords; 00069 DWORD Result; 00070 00071 FillConsoleOutputAttribute(hStdout, normal, 00072 ConsoleInfo.dwSize.X * ConsoleInfo.dwSize.Y, screen_start, &Result); 00073 00074 get_coords(&start_coords, &end_coords, &first_coords, &last_coords); 00075 FillConsoleOutputAttribute(hStdout, inverse, ConsoleInfo.dwSize.X * 00076 (last_coords.Y - first_coords.Y) + (last_coords.X - first_coords.X), 00077 first_coords, &Result); 00078 } 00079 00080 void TMouse::doClip(COORD start_coords, COORD end_coords) { 00081 // COORD screen_start = {0, 0}; 00082 COORD first_coords, last_coords; 00083 DWORD Result; 00084 00085 get_coords(&start_coords, &end_coords, &first_coords, &last_coords); 00086 00087 // Allocate the minimal size buffer 00088 int data_size = 3 + ConsoleInfo.dwSize.X * 00089 (last_coords.Y - first_coords.Y) + (last_coords.X - first_coords.X); 00090 HGLOBAL clipboard_data = GlobalAlloc(GMEM_MOVEABLE + GMEM_DDESHARE, 00091 data_size); 00092 LPVOID mem_ptr = GlobalLock(clipboard_data); 00093 00094 // Reset data_size so we can count the actual data size 00095 data_size = 0; 00096 00097 // Read the console, put carriage returns at the end of each line if 00098 // reading more than one line (Paul Brannan 9/17/98) 00099 for(int j = first_coords.Y; j <= last_coords.Y; j++) { 00100 00101 // Read line at (0,j) 00102 COORD coords; 00103 coords.X = 0; 00104 coords.Y = j; 00105 int length = ConsoleInfo.dwSize.X; 00106 00107 if(j == first_coords.Y) { 00108 coords.X = first_coords.X; 00109 length = ConsoleInfo.dwSize.X - first_coords.X; 00110 } else { 00111 // Add a carriage return to the end of the previous line 00112 *((char *)mem_ptr + data_size++) = '\r'; 00113 *((char *)mem_ptr + data_size++) = '\n'; 00114 } 00115 00116 if(j == last_coords.Y) { 00117 length -= (ConsoleInfo.dwSize.X - last_coords.X); 00118 } 00119 00120 // Read the next line 00121 ReadConsoleOutputCharacter(hStdout, (LPTSTR)((char *)mem_ptr + 00122 data_size), length, coords, &Result); 00123 data_size += Result; 00124 00125 // Strip the spaces at the end of the line 00126 if((j != last_coords.Y) && (first_coords.Y != last_coords.Y)) 00127 while(*((char *)mem_ptr + data_size - 1) == ' ') data_size--; 00128 } 00129 if(first_coords.Y != last_coords.Y) { 00130 // Add a carriage return to the end of the last line 00131 *((char *)mem_ptr + data_size++) = '\r'; 00132 *((char *)mem_ptr + data_size++) = '\n'; 00133 } 00134 00135 *((char *)mem_ptr + data_size) = 0; 00136 GlobalUnlock(clipboard_data); 00137 00138 Clipboard.Copy(clipboard_data); 00139 } 00140 00141 void TMouse::doMouse() { 00142 INPUT_RECORD InputRecord; 00143 DWORD Result; 00144 InputRecord.EventType = KEY_EVENT; // just in case 00145 while(InputRecord.EventType != MOUSE_EVENT) { 00146 if (!ReadConsoleInput(hConsole, &InputRecord, 1, &Result)) 00147 return; // uh oh! we don't know the starting coordinates! 00148 } 00149 if(InputRecord.Event.MouseEvent.dwButtonState == 0) return; 00150 if(!(InputRecord.Event.MouseEvent.dwButtonState & 00151 FROM_LEFT_1ST_BUTTON_PRESSED)) { 00152 Clipboard.Paste(); 00153 return; 00154 } 00155 00156 COORD screen_start = {0, 0}; 00157 COORD start_coords = InputRecord.Event.MouseEvent.dwMousePosition; 00158 COORD end_coords = start_coords; 00159 BOOL done = FALSE; 00160 00161 // init vars 00162 doMouse_init(); 00163 int normal_bg = ini.get_normal_bg(); 00164 int normal_fg = ini.get_normal_fg(); 00165 if(normal_bg == -1) normal_bg = 0; // FIX ME!! This is just a hack 00166 if(normal_fg == -1) normal_fg = 7; 00167 normal = (normal_bg << 4) | normal_fg; 00168 inverse = (normal_fg << 4) | normal_bg; 00169 00170 // make screen all one attribute 00171 FillConsoleOutputAttribute(hStdout, normal, ConsoleInfo.dwSize.X * 00172 ConsoleInfo.dwSize.Y, screen_start, &Result); 00173 00174 while(!done) { 00175 00176 switch (InputRecord.EventType) { 00177 case MOUSE_EVENT: 00178 switch(InputRecord.Event.MouseEvent.dwEventFlags) { 00179 case 0: // only copy if the mouse button has been released 00180 if(!InputRecord.Event.MouseEvent.dwButtonState) { 00181 doClip(start_coords, end_coords); 00182 done = TRUE; 00183 } 00184 break; 00185 00186 case MOUSE_MOVED: 00187 end_coords = InputRecord.Event.MouseEvent.dwMousePosition; 00188 move_mouse(start_coords, end_coords); 00189 break; 00190 } 00191 break; 00192 // If we are changing focus, we don't want to highlight anything 00193 // (Paul Brannan 9/2/98) 00194 case FOCUS_EVENT: 00195 return; 00196 } 00197 00198 WaitForSingleObject(hConsole, INFINITE); 00199 if (!ReadConsoleInput(hConsole, &InputRecord, 1, &Result)) 00200 done = TRUE; 00201 00202 } 00203 00204 doMouse_cleanup(); 00205 } 00206 00207 void TMouse::scrollMouse() { 00208 doMouse(); 00209 } Generated on Thu May 24 2012 04:17:29 for ReactOS by
1.7.6.1
|