# Chapter 5 of Part 2 Button Series Control Class
## Brief Introduction of Button Series Control
Button is an essential control of human computer interaction in the user
interface, and all the human computer interaction interfaces include button. In
the design of mGNCS, button use conditions under different use environments are
fully considered, and different properties and interfaces etc. are provided for
the convenience of user componentization development. Buttons in mGNCS
reconstruct built-in button control in MiniGUI 3.0 and conduct big adjustment.
Two button types are added, greatly strengthening button control. Buttons in
`MiniGNCS` include five types, common button, check box, single selection
button, menu button and color selection button. Users can select or switch
status of buttons through keyboard or mouse. Input of users will make buttons
generate notification message, and applications can send messages to the
buttons to change the status of the buttons. Each button type corresponds to
one class, which contains style, property, event, method and renderer.
Functions of the controls provided in mGNCS are usually stronger than the
functions of the controls used on `PC`, providing more configurable
information, and renderer editing is added.
In this document, button class and the properties in it will be introduced in
detail, making it convenient for the users to further understand the details of
buttons, thus buttons can be used more flexibly.
- Class hierarchical relation related to buttons
- [ `mWidget` ](MStudioMGNCSV1dot0PGENP2C3#mWidget)
* [ `mButton` ](MiniGUIProgGuidePart2Chapter06#mButton.md)
* [ `mCheckButton` ](MiniGUIProgGuidePart2Chapter06#m_CheckButton.md)
* [ `mRadioButton` ](MiniGUIProgGuidePart2Chapter06#m_RadioButton.md)
* [ `mMenuButton` ](MiniGUIProgGuidePart2Chapter06#m_MenuButton.md)
(mPopMenuMgr is used)
* [ `mColorButton` ](MiniGUIProgGuidePart2Chapter06#m_ColorButton.md)
- Control creating method
- Automatic creation: through interface designer in miniStudio, corresponding
button control is dragged. miniStudio will automatically create control and
provide visual control configuration, and at the same time, creation codes are
generated automatically.
- Manual generation: according to mGNCS control creation process, through
programming, corresponding control window class `ID` is imported and control is
generated. Manual programming sets control property and event handling.
## Button Class Renderer
mGNCS provides four types of renderers and defines renderer property setting
set. The four types of renderers correspond to four kinds of renderer property
setting set. For button class control, the four kinds of renderers defines
which renderer property can be set in the button control and which effect can
it be set to. mGNCS provides default renderer property. Of course, users can
change these properties, thus different effects can be set. That is to say,
users can change different renderer properties and create numerous renderer
examples based on the four types of renderers.
## `mButton`
- *Control window class*: `NCSCTRL_BUTTON`
- *Control English name*: Push Button
- *Brief introduction*: It is button of press down mode. On the button, the
simple ones can be represented by literals and can be marked by images, and
they can be displayed by mixture of images and literals.

To understand programming of buttons, firstly, it is necessary to understand
the status of buttons. In mGNCS, the status of buttons is divided into four
kinds, refer to appendix definition and note: `ButtonState`
[ButtonState](MiniGUIProgGuidePart2Chapter06#ButtonState.md)
### Style of `mButton`
Style of buttons includes two categories:
- Firstly, it is defining button `CHECK` status, which is press down status,
and setting is carried out through Checkable/Autocheck/ThreeDCheck in the
property;
- Secondly, it is setting button panel as displaying text or image or
coexistence if image and text, which is done mainly through options in Label
Type in property. Text by default, while layout of images and texts is set
through other properties.
`mButton` is the foundation class of all buttons, which implements `PushButton`
by default. Buttons of all other types are derived from it.
It is inherited from the style of [mWidget](MStudioMGNCSV1dot0PGENP2C3).
| *Style ID | *miniStudio property name* | *Explanation* |
| `NCSS_BUTTON_CHECKABLE` | Checkable | Set if the button can carry out `CHECKED` status conversion; if `FALSE`, `CHECK` status conversion is not carried out, and autocheck and `ThreeDCheck` are invalid |
| `NCSS_BUTTON_AUTOCHECK` | Autocheck | When `CHECKED` status conversion can be carried out, set if clicking can be carried out to automatically switch `CHECK` status |
| `NCSS_BUTTON_3DCHECK` | `ThreeDCheck` | Set button `CHECK` status as three status (unchecked-halfchecked-checked) or two status (unchecked-checked) switch |
| `NCSS_BUTTON_IMAGE` | `LabelType->Image`| Image button style, the button is label literal mode in `LabelType` by default |
| `NCSS_BUTTON_IMAGELABEL` | `LabelType->ImageLabel` | Button of horizontally arranged image text |
| `NCSS_BUTTON_VERTIMAGELABEL` | `LabelType->VertImageLabel` | Button of vertically arranged image text |
### Property of `mButton`
It is inherited from the property of [mWidget](MStudioMGNCSV1dot0PGENP2C3).
| *Property `ID` name* | *miniStudio property name* | *Type* | *Permission* | *Explanation* |
| `NCSP_BUTTON_ALIGN` | Align | [Alignment enumeration value](MStudioMGNCSV1dot0PGENAppC#AlignValues) | `RW` | Content on the button (image or literal) is aligned with the button according to the set mode in horizontal direction |
| `NCSP_BUTTON_VALIGN` | `VAlign` | [Alignment enumeration value](MStudioMGNCSV1dot0PGENAppC#AlignValues) | `RW` | Content on the button (image or literal) is aligned with the button according to the set mode in vertical direction, and the alignment value is top – 0, bottom – 1, center – 2 |
| `NCSP_BUTTON_WORDWRAP` | Wordwrap | int | `RW` | Automatic wrap property of the literals on the button, when the single line length of the literal content is bigger than the control width, automatic wrap can be selected. `TRUE`: automatic wrap `FALSE`: single line, and the exceeding part is not displayed |
| `NCSP_BUTTON_IMAGE` | Image | `PBITMAP` | `RW` | Image, corresponding to button property pbmp, which is image pointer, it must be valid when `NCSS_BUTTON_IMAGE` or `NCSS_BUTTON_IMAGELABEL` or `NCSS_BUTTON_VERTIMAGELABEL` is set |
| `NCSP_BUTTON_CHECKSTATE`| 无 | [mButtonCheckState](MStudioMGNCSV1dot0PGP2C5#ButtonCheckState)| `RW` | Set or get check status, valid when `NCSS_BUTTON_CHECKABLE` is set, `NCS_BUTTON_HALFCHECKED` is regarded as valid value when `NCSS_BUTTON_3DCHECK` is set |
| `NCSP_BUTTON_IMAGE_SIZE_PERCENT`| `ImageSizePercent` | int | `RW` | Under the style of coexistence of image and text, set proportion of image on the control (take value 15~85, representing 15% to 85%), and the remaining is occupied by the text |
| `NCSP_BUTTON_GROUPID`| `GroupID` | int | `RW` | When there is `NCSS_BUTTON_CHECKABLE` style, `ID` of a `mButtonGroup` can be set to the window, it will automatically get a corresponding `mButtonGroup` object and set |
| `NCSP_BUTTON_GROUP`| 无 | `mButtonGroup` *|RW| When there is `NCSS_BUTTON_CHECKABLE` style, set a `mButtonGroup` object pointer, and all the buttons adding to the group has the automatic switching ability of Radio style |
### Event of `mButton`
It is inherited from the event of [mWidget](MStudioMGNCSV1dot0PGENP2C3).
| *Event notification code* | *Explanation* | *Parameter* |
| `NCSN_BUTTON_PUSHED` | Key pressed down | |
| `NCSN_BUTTON_STATE_CHANGED` | After status changes | New status |
Note, the control inherits `NCSN_WIDGET_CLICKED` event of the parent class.
### Renderer of `mButton`
*For the usage of renderer, see [look and feel
renderer](MStudioMGNCSV1dot0PGENP2C2)*.
#### `mButton` Classic renderer
The basic style under classic renderer is as shown in the figure below:
Drawing of `mButton` Classic renderer is as below: for the drawing of non
client area, please refer to the renderer of
[mWidget](MStudioMGNCSV1dot0PGENP2C3#mWidget).
| *Property ID | *Meaning* | *miniStudio property name* | *Value type* | *Schematic diagram of the valid region* | *Value range* |
| `NCS_FGC_3DBODY` | Text foreground color | `FgColor3DBody` | `DWORD(ARGB`) || |
| `NCS_BGC_3DBODY` | Background color | `BgColor3DBody` | `DWORD(ARGB`) |
| |
| `NCS_FGC_DISABLED_ITEM` | Text foreground color when the window is invalid | `TextDisableColor` | `DWORD(ARGB`) |
| |
| `NCS_BGC_DISABLED_ITEM` | background color when the window is invalid | `BgColorDisable` | `DWORD(ARGB`) |
| |
- High light effect: through enhancing the brightness of the background color
(NCS_BGC_3DBODY), as the high light color
- check effect: implement through drawing invaginated border
- Three status Check effect: implement half selection through drawing high
light color in the invaginated border
Schematic diagram:

### `mButton` Skin Renderer
Refer to [Appendix B: Specification for the Image Resources Used by Skin
Renderer](MStudioMGNCSV1dot0PGENAppB#mButton).
#### `mButton` Fashion Renderer
For the drawing of non client area, please refer to the drawing of Fashion
renderer of [mWidget](MStudioMGNCSV1dot0PGENP2C3#mWidget).
| *Property ID | *Meaning* | *miniStudio property name* | *Value type* | *Schematic diagram of the valid region* | *Value range* |
| `NCS_FGC_3DBODY` | Text foreground color | `FgColor3DBody` | `DWORD(ARGB`) | Same as Classic renderer | |
| `NCS_FGC_DISABLED_ITEM` | Text foreground color when the window is invalid| `TextDisableColor` | `DWORD(ARGB`) | Same as Classic renderer | |
| `NCS_BGC_3DBODY` | Background color | `BgColor3DBody` | `DWORD(ARGB`) | | |
| `NCS_BGC_DISABLED_ITEM` | Text background color when the window is invalid | `BgColorDisable` | `DWORD(ARGB`) |
| |
| `NCS_MODE_BGC` | Gradual change fill mode | `GradientMode` | int |
| [GradientMode](MStudioMGNCSV1dot0PGP2C5#GrandientMode) |
| `NCS_METRICS_3DBODY_ROUNDX` | Window rectangle round corner X radius | `RoundX` | int | | 0 to 1/2 of the window width |
| `NCS_METRICS_3DBODY_ROUNDY` | Window rectangle round corner Y radius | `RoundY` | int| | 0 to 1/2 of the window height |
- Gradual change color: the gradual change color gives different brightness
factor from the ground color (NCS_BGC_3DBODY or `NCS_BGC_DISABLED_ITEM`), and
calculates the two objective colors. Gradually change from the center (ground
color) to the two sides or top and bottom (highlighted color achieved through
calculation)
- High light color: after the ground color is highlighted, the gradual change
color calculates to obtain on the foundation of this
- Representing method of check status: after the ground color undergoes
darkening processing, calculate the gradual change color
- Representing method of three status check: besides the method is the same as
above in check status, in half selection status, use the window ground color
(`NCS_BGC_WINDOW`) as the whole ground color to draw
Schematic diagram:

#### `mButton` Flat Renderer
For the drawing of non client area, please refer to the drawing of Flat
renderer of [mWidget](MStudioMGNCSV1dot0PGENP2C3#mWidget).
| *Property ID | *Meaning* | *miniStudio property name* | *Value type* | *Schematic diagram of the valid region* | *Value range* |
| `NCS_FGC_3DBODY` | Text foreground color | `FgColor3DBody` | `DWORD(ARGB`) | Same as Classic renderer | |
| `NCS_FGC_DISABLED_ITEM` | Text foreground color when the window is invalid | `TextDisableColor` | `DWORD(ARGB`) | Same as Classic renderer | |
| `NCS_BGC_3DBODY` | background color | `BgColor3DBody` | `DWORD(ARGB`) | Same as Classic renderer |
| `NCS_METRICS_3DBODY_ROUNDX` | Window rectangle round corner X radius | `RoundX` | int | | 0 to 1/2 of the window width |
| `NCS_METRICS_3DBODY_ROUNDY` | Window rectangle round corner Y radius | `RoundY` | int| | 0 to 1/2 of the window height |
- High light: draw small prompting symbols to implement around the control
- check status: draw lines at right-bottom edition, and compose inverted “L”
realization
- check representing method of three status: in half selection status, draw
lines at left-top, forming fell flat “L”
Schematic diagram:

### Programming Example of `mButton`
- Operation screen shot:

- This program uses Fashion renderer to create buttons of four different
styles, which are common button, image button, Autocheck style button and three
status button.
- Complete example code of common button: [button.c](%ATTACHURL%/button.c.txt)
##### List 1 button.c
##### List 1 button.c
List p2c5-1 button.c
- Define common button ```cpp %INCLUDE{"%ATTACHURL%/button.c.txt" pattern="^.*?//START_DCL_DEF_PUSHBUTTON(.*?)//END_DCL_DEF_PUSHBUTTON.*"}% ``` - Define Image button, generally it is handled in `onCreate` event of the main window ```cpp %INCLUDE{"%ATTACHURL%/button.c.txt" pattern="^.*?//START_DCL_IMAGEBUTTON(.*?)//END_DCL_IMAGEBUTTON.*"}% ``` - Load and set Image ```cpp %INCLUDE{"%ATTACHURL%/button.c.txt" pattern="^.*?//START_SET_IMAGE(.*?)//END_STE_IMAGE.*"}% ``` - Define button of Autocheck style ```cpp %INCLUDE{"%ATTACHURL%/button.c.txt" pattern="^.*?//START_DCL_AUTOCHECKBTN(.*?)//END_DCL_AUTOCHECKBTN.*"}% ``` - Define button of three status check style ```cpp %INCLUDE{"%ATTACHURL%/button.c.txt" pattern="^.*?//START_DCL_3DAUTOCHECKBTN(.*?)//END_DCL_3DAUTOCHECKBTN.*"}% ``` ## `mCheckButton` - *Control window class*: `NCSCTRL_CHECKBUTTON` - *Control English name*: `CheckButton` - *Brief introduction*: Check box button, mainly used on multi-selection occasion. The common pattern is a box, and the user checks or unchecks the box.  ### Property of `mCheckButton` It is inherited from the property of mButton`. ### Event of `mCheckButton` It is inherited from the event of mButton`. ### Renderers of `mCheckButton` - For the usage of renderers, see [look and feel renderer](MStudioMGNCSV1dot0PGENP2C2) #### `mCheckButton` Classic Renderer - Drawing of renderer in the `mCheckButton` Classic text region is as below: for the drawing of non client area, please refer to the renderer of [mWidget](MStudioMGNCSV1dot0PGP2C3#mWidget). | *Property ID | *Meaning* | *miniStudio property name* | *Value type* | *Schematic diagram of the valid region* | *Value range* | | `NCS_FGC_3DBODY` | Text foreground color | `FgColor3DBody` | `DWORD(ARGB`) |