WOLEDIT.CPP (4949B)
1 // 2 // Copyright 2020 Electronic Arts Inc. 3 // 4 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free 5 // software: you can redistribute it and/or modify it under the terms of 6 // the GNU General Public License as published by the Free Software Foundation, 7 // either version 3 of the License, or (at your option) any later version. 8 9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 10 // in the hope that it will be useful, but with permitted additional restrictions 11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 12 // distributed with this program. You should have received a copy of the 13 // GNU General Public License along with permitted additional restrictions 14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection 15 16 #ifdef WOLAPI_INTEGRATION 17 18 /*************************************************************************** 19 * WOLEditClass -- Derived from EditClass, includes changes I wanted for 20 * wolapi integration stuff. 21 * Note: An editbox of this class cannot be made read-only. See comment below. 22 * HISTORY: 07/17/1998 ajw : Created. 23 *=========================================================================*/ 24 25 #include "WOLEdit.h" 26 27 //#include "WolDebug.h" 28 29 bool bTabKeyPressedHack = false; 30 31 //*********************************************************************************************** 32 void WOLEditClass::Draw_Text( char const * text ) 33 { 34 // Only difference between this and EditClass: cursor shows up when 35 // string is at MaxLength. 36 37 TextPrintType flags; 38 39 if (Has_Focus()) { 40 flags = TPF_BRIGHT_COLOR; 41 } else { 42 flags = (TextPrintType)0; 43 } 44 45 Conquer_Clip_Text_Print(text, X+1, Y+1, Color, TBLACK, TextFlags | flags, Width-2); 46 47 if (Has_Focus() && // strlen(text) < MaxLength && 48 (String_Pixel_Width(text) + String_Pixel_Width ("_") < Width-2) ) { 49 Conquer_Clip_Text_Print( "_", X+1+String_Pixel_Width(text), Y+1, Color, TBLACK, TextFlags | flags); 50 } 51 } 52 53 //*********************************************************************************************** 54 // Override of EditClass::Action, because the base class does not behave correctly in certain circumstances. 55 // (Escape key is being processed as enter key.) 56 // Again, I'm not about to change the base class directly, as I'm trying to have as minimal an affect as possible on 57 // the current game code. -ajw 58 int WOLEditClass::Action(unsigned flags, KeyNumType & key) 59 { 60 // (Mostly duplicated from base class ::Action) 61 /* For some painful reason, IsReadOnly is private in the base class, so I can't do the following. 62 For this reason, don't make a WOLEditClass edit box read-only. 63 64 // 65 // If this is a read-only edit box, it's a display-only device 66 // 67 if (IsReadOnly) { 68 return(false); 69 } 70 */ 71 72 //debugprint( "WOLEditClass::Action this=%i, flags=0x%x, key=0x%x\n", this, flags, key ); 73 // 74 // If the left mouse button is pressed over this gadget, then set the focus to 75 // this gadget. The event flag is cleared so that no button ID number is returned. 76 // 77 if ((flags & LEFTPRESS)) { 78 flags &= ~LEFTPRESS; 79 Set_Focus(); 80 Flag_To_Redraw(); // force to draw cursor 81 } 82 83 // 84 // Handle keyboard events here. Normally, the key is added to the string, but if the 85 // RETURN key is pressed, then the button ID number is returned from the Input() 86 // function. 87 // 88 if ((flags & KEYBOARD) && Has_Focus()) { 89 90 // 91 // Process the keyboard character. If indicated, consume this keyboard event 92 // so that the edit gadget ID number is not returned. 93 // 94 if (key == KN_ESC) { 95 96 Clear_Focus(); 97 flags = 0; 98 99 } else { 100 #ifdef WIN32 101 102 KeyASCIIType ascii = (KeyASCIIType)(Keyboard->To_ASCII(key) & 0xff); 103 104 // 105 // Allow numeric keypad presses to map to ascii numbers 106 // 107 if ((key & WWKEY_VK_BIT) && ascii >='0' && ascii <= '9') { 108 109 key = (KeyNumType)(key & ~WWKEY_VK_BIT); 110 if ( (!(flags & LEFTRELEASE)) && (!(flags & RIGHTRELEASE))) { 111 if (Handle_Key (ascii) ) { 112 flags &= ~KEYBOARD; 113 key = KN_NONE; 114 } 115 } 116 } else { 117 // 118 // Filter out all special keys except return and backspace 119 // 120 if ((!(key & WWKEY_VK_BIT) && ascii >= ' ' && ascii <= 255) 121 || key == KN_RETURN || key == KN_BACKSPACE) { 122 123 124 125 if ((!(flags & LEFTRELEASE)) && (!(flags & RIGHTRELEASE))) { 126 if (Handle_Key(Keyboard->To_ASCII(key))) { 127 flags &= ~KEYBOARD; 128 key = KN_NONE; 129 } 130 } 131 } else { 132 if( key == KN_TAB ) 133 { 134 bTabKeyPressedHack = true; 135 } 136 flags &= ~KEYBOARD; 137 key = KN_NONE; 138 } 139 } 140 } 141 142 #else //WIN32 143 if (Handle_Key(Keyboard->To_ASCII(key))) { 144 flags &= ~KEYBOARD; 145 key = KN_NONE; 146 } 147 } 148 #endif //WIN32 149 } 150 else 151 { 152 // ajw added 153 // if( key == ( KN_ESC | WWKEY_RLS_BIT ) && ( key & WWKEY_ALT_BIT ) ) 154 // { 155 //Clear_Focus(); 156 flags = 0; 157 key = KN_NONE; 158 // } 159 } 160 161 return(ControlClass::Action(flags, key)); 162 } 163 164 #endif