WOLEDIT.CPP 4.8 KB

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