btn.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. //////////////////////////////////////////////////////////////////////////////
  19. //
  20. // BTN.CPP
  21. //
  22. // History:
  23. // 08/07/96 JMI Started.
  24. //
  25. // 08/12/96 JMI Now utilizes CGuiItem::DrawText to draw text and over-
  26. // rides CGuiItem's default justification to CENTERED.
  27. //
  28. // 09/24/96 JMI Now draws border only once during a compose.
  29. //
  30. // 09/24/96 JMI Changed all BLU_MB?_* macros to RSP_MB?_* macros.
  31. //
  32. // 10/31/96 JMI Changed:
  33. // Old label: New label:
  34. // ========= =========
  35. // CBtn RBtn
  36. // CImage RImage
  37. // CGuiItem RGuiItem
  38. // CENTERED Centered
  39. //
  40. // 11/27/96 JMI Added initialization of m_type to identify this type
  41. // of GUI item.
  42. //
  43. // 12/19/96 JMI Uses new m_justification (as m_sJustification) and now
  44. // uses new DrawText() call (takes 4 parms instead of 3).
  45. //
  46. // 01/01/96 JMI HotCall() now calls the base class to do what it used
  47. // to with the exception of the one thing it still does --
  48. // Compose(). Also, Compose() no longer sets hot area
  49. // (now done by base class).
  50. //
  51. // 01/04/96 JMI Upgraded HotCall() to new CursorEvent(). This upgrade
  52. // is in response to RGuiItem now using relative RHots.
  53. // Now m_hot.m_sX/Y is parent item relative just like
  54. // m_sX/Y. This should simplify a lot of stuff and even
  55. // fix some odd features like being able to click a GUI
  56. // item that exceeds the boundary of its parent. This fix
  57. // will be essential for the not-yet-existent RListBox since
  58. // it will most likely scroll many children through a small
  59. // client area.
  60. // Now there are two regions associated with cursor events.
  61. // The first is the 'hot' area. This is the area that m_hot
  62. // is set to include. Child items can only receive cursor
  63. // events through this area. The second is the 'event' area.
  64. // This is the area where the item really is actually con-
  65. // cerned with cursor events. Example: For a Dlg, the
  66. // entire window is the 'hot' area and the title bar is the
  67. // 'event' area.
  68. //
  69. // 03/19/97 JMI Converted to using the RHot::m_iecUser (was using
  70. // RHot::m_epcUser) so HotCall and CursorEvent now take
  71. // RInputEvent ptrs.
  72. //
  73. // 03/28/97 JMI RSP_MB0_DOUBLECLICK is now treated the same as
  74. // RSP_MB0_PRESSED.
  75. //
  76. //////////////////////////////////////////////////////////////////////////////
  77. //
  78. // This a GUI item that is based on the basic RGuiItem.
  79. // This overrides HotCall() to get information about where a click in its CHot
  80. // occurred.
  81. // This overrides Compose() to add text.
  82. //
  83. // Enhancements/Uses:
  84. // To change the look of a button when pressed, you may want to override the
  85. // Compose() or DrawBorder() in a derived class.
  86. // To change the background of a button, see RGuiItem.
  87. // To get a callback on a click/release pair in the button, set m_bcUser.
  88. //
  89. //////////////////////////////////////////////////////////////////////////////
  90. //////////////////////////////////////////////////////////////////////////////
  91. // Headers.
  92. //////////////////////////////////////////////////////////////////////////////
  93. #include "Blue.h"
  94. #ifdef PATHS_IN_INCLUDES
  95. #include "ORANGE/GUI/btn.h"
  96. #else
  97. #include "btn.h"
  98. #endif // PATHS_IN_INCLUDES
  99. //////////////////////////////////////////////////////////////////////////////
  100. // Module specific macros.
  101. //////////////////////////////////////////////////////////////////////////////
  102. // Sets val to def if val is -1.
  103. #define DEF(val, def) ((val == -1) ? def : val)
  104. //////////////////////////////////////////////////////////////////////////////
  105. // Module specific typedefs.
  106. //////////////////////////////////////////////////////////////////////////////
  107. //////////////////////////////////////////////////////////////////////////////
  108. // Module specific (static) variables.
  109. //////////////////////////////////////////////////////////////////////////////
  110. //////////////////////////////////////////////////////////////////////////////
  111. // Construction/Destruction.
  112. //////////////////////////////////////////////////////////////////////////////
  113. //////////////////////////////////////////////////////////////////////////////
  114. //
  115. // Default constructor.
  116. //
  117. //////////////////////////////////////////////////////////////////////////////
  118. RBtn::RBtn()
  119. {
  120. // Override RGuiItem's default justification.
  121. m_justification = RGuiItem::Centered;
  122. m_type = Btn; // Indicates type of GUI item.
  123. }
  124. //////////////////////////////////////////////////////////////////////////////
  125. //
  126. // Destructor.
  127. //
  128. //////////////////////////////////////////////////////////////////////////////
  129. RBtn::~RBtn()
  130. {
  131. }
  132. ////////////////////////////////////////////////////////////////////////
  133. // Methods.
  134. ////////////////////////////////////////////////////////////////////////
  135. ////////////////////////////////////////////////////////////////////////
  136. //
  137. // Compose item.
  138. //
  139. ////////////////////////////////////////////////////////////////////////
  140. void RBtn::Compose( // Returns nothing.
  141. RImage* pim /*= NULL*/) // Dest image, uses m_im if NULL.
  142. {
  143. if (pim == NULL)
  144. {
  145. pim = &m_im;
  146. }
  147. if (m_sPressed != FALSE)
  148. {
  149. // Invert border.
  150. m_sInvertedBorder = TRUE;
  151. }
  152. else
  153. {
  154. m_sInvertedBorder = FALSE;
  155. }
  156. // Call base (draws border and background).
  157. RGuiItem::Compose(pim);
  158. // Draw btn stuff.
  159. short sX, sY, sW, sH;
  160. // Get client relative to border so we know where to
  161. // put the text.
  162. GetClient(&sX, &sY, &sW, &sH);
  163. // Draw text.
  164. DrawText(sX, sY, sW, sH, pim);
  165. }
  166. ////////////////////////////////////////////////////////////////////////
  167. //
  168. // Cursor event notification.
  169. // Events in event area.
  170. // (virtual).
  171. //
  172. ////////////////////////////////////////////////////////////////////////
  173. void RBtn::CursorEvent( // Returns nothing.
  174. RInputEvent* pie) // In: Most recent user input event.
  175. // Out: pie->sUsed = TRUE, if used.
  176. {
  177. // Call base.
  178. RGuiItem::CursorEvent(pie);
  179. switch (pie->sEvent)
  180. {
  181. case RSP_MB0_DOUBLECLICK:
  182. case RSP_MB0_PRESSED:
  183. // If not inverted already . . .
  184. if (m_sInvertedBorder == FALSE)
  185. {
  186. // Recompose.
  187. Compose();
  188. }
  189. // Note that we used it.
  190. pie->sUsed = TRUE;
  191. break;
  192. case RSP_MB0_RELEASED:
  193. // If we were inverted . . .
  194. if (m_sInvertedBorder != FALSE)
  195. {
  196. // Recompose.
  197. Compose();
  198. }
  199. // Note that we used it.
  200. pie->sUsed = TRUE;
  201. break;
  202. }
  203. }
  204. ////////////////////////////////////////////////////////////////////////
  205. // Querries.
  206. ////////////////////////////////////////////////////////////////////////
  207. //////////////////////////////////////////////////////////////////////////////
  208. // EOF
  209. //////////////////////////////////////////////////////////////////////////////