ccheckbox.hxx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /****************************************************************************
  2. * apps/include/graphics/nxwidgets/ccheckbox.hxx
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. /****************************************************************************
  21. *
  22. * Portions of this package derive from Woopsi (http://woopsi.org/) and
  23. * portions are original efforts. It is difficult to determine at this
  24. * point what parts are original efforts and which parts derive from Woopsi.
  25. * However, in any event, the work of Antony Dzeryn will be acknowledged
  26. * in all NxWidget files. Thanks Antony!
  27. *
  28. * Copyright (c) 2007-2011, Antony Dzeryn
  29. * All rights reserved.
  30. *
  31. * Redistribution and use in source and binary forms, with or without
  32. * modification, are permitted provided that the following conditions are met:
  33. *
  34. * * Redistributions of source code must retain the above copyright
  35. * notice, this list of conditions and the following disclaimer.
  36. * * Redistributions in binary form must reproduce the above copyright
  37. * notice, this list of conditions and the following disclaimer in the
  38. * documentation and/or other materials provided with the distribution.
  39. * * Neither the names "Woopsi", "Simian Zombie" nor the
  40. * names of its contributors may be used to endorse or promote products
  41. * derived from this software without specific prior written permission.
  42. *
  43. * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
  44. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  45. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  46. * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
  47. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  48. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  49. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  50. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  51. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  52. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  53. *
  54. ****************************************************************************/
  55. #ifndef __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CCHECKBOX_HXX
  56. #define __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CCHECKBOX_HXX
  57. /****************************************************************************
  58. * Included Files
  59. ****************************************************************************/
  60. #include <nuttx/config.h>
  61. #include <stdint.h>
  62. #include <stdbool.h>
  63. #include <nuttx/nx/nxglib.h>
  64. #include "graphics/nxwidgets/cbutton.hxx"
  65. #include "graphics/nxwidgets/cwidgetstyle.hxx"
  66. /****************************************************************************
  67. * Pre-Processor Definitions
  68. ****************************************************************************/
  69. /****************************************************************************
  70. * Implementation Classes
  71. ****************************************************************************/
  72. #if defined(__cplusplus)
  73. namespace NXWidgets
  74. {
  75. class CWidgetControl;
  76. /**
  77. * Class representing a checkbox. Like radio buttons, checkboxes
  78. * are tri-state - off, on and "mu". The mu state cannot be enabled by
  79. * a user - it can only be set by the developer.
  80. */
  81. class CCheckBox : public CButton
  82. {
  83. public:
  84. /**
  85. * Enum listing all possible checkbox states.
  86. */
  87. enum CheckBoxState
  88. {
  89. CHECK_BOX_STATE_OFF = 0, /**< Checkbox is unticked */
  90. CHECK_BOX_STATE_ON = 1, /**< Checkbox is ticked */
  91. CHECK_BOX_STATE_MU = 2 /**< Checkbox is in the third state */
  92. };
  93. protected:
  94. CheckBoxState m_state; /**< The state of the checkbox */
  95. /**
  96. * Draw the area of this widget that falls within the clipping region.
  97. * Called by the redraw() function to draw all visible regions.
  98. *
  99. * @param port The CGraphicsPort to draw to.
  100. * @see redraw()
  101. */
  102. virtual void drawContents(CGraphicsPort *port);
  103. /**
  104. * Draw the area of this widget that falls within the clipping region.
  105. * Called by the redraw() function to draw all visible regions.
  106. *
  107. * @param port The CGraphicsPort to draw to.
  108. * @see redraw()
  109. */
  110. virtual void drawBorder(CGraphicsPort *port);
  111. /**
  112. * Toggles the state of the checkbox.
  113. *
  114. * @param x The x coordinate of the click.
  115. * @param y The y coordinate of the click.
  116. */
  117. virtual void onClick(nxgl_coord_t x, nxgl_coord_t y);
  118. /**
  119. * Copy constructor is protected to prevent usage.
  120. */
  121. inline CCheckBox(const CCheckBox &checkBox) : CButton(checkBox) { }
  122. public:
  123. /**
  124. * Constructor.
  125. *
  126. * @param pWidgetControl The widget control for the display.
  127. * @param x The x coordinate of the checkbox, relative to its parent.
  128. * @param y The y coordinate of the checkbox, relative to its parent.
  129. * @param width The width of the checkbox.
  130. * @param height The height of the checkbox.
  131. * @param style The style that the widget should use. If this is not
  132. * specified, the widget will use the values stored in the global
  133. * g_defaultWidgetStyle object. The widget will copy the properties of
  134. * the style into its own internal style object.
  135. */
  136. CCheckBox(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y,
  137. nxgl_coord_t width, nxgl_coord_t height,
  138. CWidgetStyle *style = (CWidgetStyle *)NULL);
  139. /**
  140. * Destructor.
  141. */
  142. virtual inline ~CCheckBox(void) { }
  143. /**
  144. * Get the current state of the checkbox.
  145. *
  146. * @return The state of the checkbox.
  147. */
  148. virtual inline const CheckBoxState getState(void) const
  149. {
  150. return m_state;
  151. }
  152. /**
  153. * Set the state of the checkbox.
  154. *
  155. * @param state The new checkbox state.
  156. */
  157. virtual void setState(CheckBoxState state);
  158. };
  159. }
  160. #endif // __cplusplus
  161. #endif // __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CCHECKBOX_HXX