CONTROL.CPP 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. /* $Header: F:\projects\c&c\vcs\code\control.cpv 2.18 16 Oct 1995 16:51:38 JOE_BOSTIC $ */
  15. /***********************************************************************************************
  16. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  17. ***********************************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : CONTROL.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : 01/15/95 *
  26. * *
  27. * Last Update : January 19, 1995 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * ControlClass::Action -- Normal action for control gaget objects. *
  32. * ControlClass::ControlClass -- Constructor for control class objects. *
  33. * ControlClass::Draw_Me -- Draw logic for the control class object. *
  34. * ControlClass::Get_ID -- Gets the ID number for this gadget. *
  35. * ControlClass::Make_Peer -- Assigns a peer gadget to this gadget. *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #include "function.h"
  38. /***********************************************************************************************
  39. * ControlClass::ControlClass -- Constructor for control class objects. *
  40. * *
  41. * This is the normal constructor for control class objects. At this level, it only needs *
  42. * to record the ID number assigned to this button. *
  43. * *
  44. * INPUT: id -- The ID number for this gadget. If the ID number specified is 0, then *
  45. * this tells the system that no special ID code should be returned. *
  46. * *
  47. * x,y -- Pixel coordinate of upper left corner of gadget's region. *
  48. * *
  49. * w,h -- Pixel dimensions of the gadget's region. *
  50. * *
  51. * flags -- The input event flags that this gadget recognizes. *
  52. * *
  53. * sticky-- This this a "sticky" gadget? A sticky gadget is one that takes over the *
  54. * gadget list while the mouse button is held down, if the mouse button was *
  55. * initially clicked over its region. This is the behavior of "normal" *
  56. * buttons in Windows. *
  57. * *
  58. * OUTPUT: none *
  59. * *
  60. * WARNINGS: none *
  61. * *
  62. * HISTORY: *
  63. * 01/15/1995 JLB : Created. *
  64. *=============================================================================================*/
  65. ControlClass::ControlClass(unsigned id, int x, int y, int w, int h, unsigned flags, int sticky)
  66. : GadgetClass(x, y, w, h, flags, sticky)
  67. {
  68. ID = id;
  69. Peer = 0;
  70. }
  71. /***********************************************************************************************
  72. * ControlClass::Action -- Normal action for control gaget objects. *
  73. * *
  74. * This function gets called when the input event that this control gadget is looking for *
  75. * occurs. In such a case, the return key code value is changed to the gaget's ID number *
  76. * with the special button bit flag attached. *
  77. * *
  78. * INPUT: flags -- The event that triggered this function call. If this value is NULL, then *
  79. * this is a forced (probably due to the sticky flag) call and the key code *
  80. * is not altered. *
  81. * *
  82. * key -- Reference to the key code that will be returned by the controlling *
  83. * Input() function. *
  84. * *
  85. * OUTPUT: bool; Should futher list processing be aborted? *
  86. * *
  87. * WARNINGS: none *
  88. * *
  89. * HISTORY: *
  90. * 01/15/1995 JLB : Created. *
  91. *=============================================================================================*/
  92. int ControlClass::Action(unsigned flags, KeyNumType & key)
  93. {
  94. /*
  95. ** If there is a peer link established, inform that gadget of this
  96. ** action call.
  97. */
  98. if (Peer) {
  99. Peer->Peer_To_Peer(flags, key, *this);
  100. }
  101. /*
  102. ** Only if the flags indicate that a recognized action has occured, do the
  103. ** normal processing of this gadget and set return value to the gadget ID.
  104. */
  105. if (flags) {
  106. if (ID) {
  107. key = (KeyNumType)(ID | KN_BUTTON);
  108. } else {
  109. key = KN_NONE;
  110. }
  111. }
  112. return(GadgetClass::Action(flags, key));
  113. }
  114. /***********************************************************************************************
  115. * ControlClass::Make_Peer -- Assigns a peer gadget to this gadget. *
  116. * *
  117. * This function will assign another gadget to this one. That other gadget will receive *
  118. * notification of any Action() call to this gadget. Presumably, this is how one gadget *
  119. * can automatically adapt to changes in another. Say for example, a slider bar can affect *
  120. * the list box it is attached to. *
  121. * *
  122. * INPUT: gadget -- The gadget to inform when any Action() function is called. *
  123. * *
  124. * OUTPUT: none *
  125. * *
  126. * WARNINGS: none *
  127. * *
  128. * HISTORY: *
  129. * 01/16/1995 JLB : Created. *
  130. *=============================================================================================*/
  131. void ControlClass::Make_Peer(GadgetClass & gadget)
  132. {
  133. Peer = &gadget;
  134. }
  135. /***********************************************************************************************
  136. * ControlClass::Get_ID -- Gets the ID number for this gadget. *
  137. * *
  138. * This function will query and return with the ID number for this gadget. It is primarily *
  139. * used by the Extract_Gadget() function. *
  140. * *
  141. * INPUT: none *
  142. * *
  143. * OUTPUT: Returns with the ID number for this gadget. If zero is returned, this means that *
  144. * no ID was assigned to this gadget. This is a special case since a zero value will *
  145. * never be returned as a pseudo-key as is done with non-zero values. *
  146. * *
  147. * WARNINGS: none *
  148. * *
  149. * HISTORY: *
  150. * 01/16/1995 JLB : Created. *
  151. *=============================================================================================*/
  152. unsigned ControlClass::Get_ID(void) const
  153. {
  154. return(ID);
  155. }
  156. /***********************************************************************************************
  157. * ControlClass::Draw_Me -- Draw logic for the control class object. *
  158. * *
  159. * This is called when the control object might need to be redrawn or when redrawing is *
  160. * necessary. Since at this level of the class heirarchy, no actual drawing occurs, this *
  161. * routine doesn't perform any rendering. It does, however, inform any peer attached *
  162. * object that a Draw_Me function has been called. Presumably, the attached peer gadget *
  163. * might very well need to be redrawn as a result of some action by this gadget. Since this *
  164. * gadget might, more than likely, be of the "sticky" variety, a normal call to Draw_Me *
  165. * for the other gadget will not occur. It must rely on the call by this routine in order *
  166. * to update correctly. A typical example of this would be a slider that is attached to *
  167. * a list box. As the slider is being drug around, the attached list box must be redrawn. *
  168. * *
  169. * INPUT: forced -- Should the redraw be forced regardless of the redraw flag? *
  170. * *
  171. * OUTPUT: bool; Was the gadget redrawn? *
  172. * *
  173. * WARNINGS: none *
  174. * *
  175. * HISTORY: *
  176. * 01/16/1995 JLB : Created. *
  177. *=============================================================================================*/
  178. int ControlClass::Draw_Me(int forced)
  179. {
  180. if (Peer) {
  181. Peer->Draw_Me();
  182. }
  183. return(GadgetClass::Draw_Me(forced));
  184. }