# The MIT License (MIT)
#
# Copyright (C) 2026 Scott Duensing
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

.section Widgets
.topic widget.checkbox
.title Checkbox
.toc 0 Checkbox
.index Checkbox
.index wgtCheckbox
.index wgtCheckboxIsChecked
.index wgtCheckboxSetChecked

.h2 Checkbox

A toggle control with a text label. Clicking toggles between checked and unchecked states. Fires onChange each time the state flips. Supports accelerator keys (via '&' in the text) and keyboard toggle via Space or Enter when focused.

The check mark is drawn as an "X" pattern rather than a traditional checkmark glyph. The focus rectangle wraps the label text (not the box), matching the Windows 3.1 convention.

Header: widgets/checkbox.h

.h3 Creation

.code
WidgetT *cb = wgtCheckbox(parent, "Enable &logging");
.endcode

.h3 API Functions

.table
  Function                                                Description
  --------                                                -----------
  WidgetT *wgtCheckbox(parent, text)                      Create a checkbox with the given label text.
  bool wgtCheckboxIsChecked(w)                            Returns true if the checkbox is checked.
  void wgtCheckboxSetChecked(w, checked)                  Set the checked state programmatically. Triggers a repaint but does NOT fire onChange.
.endtable

.h3 API Struct (wgtRegisterApi "checkbox")

.table
  Slot          Function
  ----          --------
  create        wgtCheckbox
  isChecked     wgtCheckboxIsChecked
  setChecked    wgtCheckboxSetChecked
.endtable

.h3 Properties (BASIC Interface)

.table
  Property     Type       Access       Description
  --------     ----       ------       -----------
  Value        Boolean    Read/Write   Whether the checkbox is checked.
.endtable

Label text is managed via the standard wgtSetText() / wgtGetText() interface. BASIC code uses the generic "Caption" or "Text" property.

.h3 Methods

No widget-specific methods.

.h3 Events

.table
  Callback     Description
  --------     -----------
  onClick      Fires when clicked (after the toggle has already applied).
  onChange     Fires when the checked state changes (mouse click or keyboard toggle).
.endtable

.h3 Default Event

"Click" (VB basName: CheckBox).
