WOLEDIT.CPP 4.7 KB

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