# Futurebasic/Language/Reference/appearance button
## Appearance Button
### Statement

✔ Appearance χ Standard χ Console

### Revided

Feb 2002 (Release 6)

### Description

The appearance button statement puts a new control in the current output window, or alters an existing control's characteristics. After you create a button using the appearance button statement, you can use the dialog function to determine whether the user has clicked it. You can use the button close statement if you want to dispose of the button without closing the window.
When you first create a button with a specific ID (in a given window), you must specify all the parameters up to and including type. If you later want to modify that button's characteristics, execute appearance button again with the same ID, and specify one or more of the other parameters (except type, which cannot be altered). The button will be redrawn using the new characteristics that you specified; any parameter that you don't specify will not be altered.
| id& | a positive or negative integer whose absolute value is in the range 1 through 2147483647. The number you assign must be different from all other scroll bars or buttons in that window. Negative values build invisible buttons. Positive values build visible buttons. |
| state | The state may be: _grayBtn (0/disabled) _activebtn (1/default/active) _markedBtn (2/selected) |
| value, min, max | generally an integer value for the initial, minimum, and maximum values of a control |
| title$ | a string expression. This parameter is not used to set the text of buttons defined with _kControlStaticTextProc or _kControlEditTextProc. See def SetButtonTextString for information on how this may be accomplished. |
| rect | a rectangle in local window coordinates. You can express it in either of two forms: (x1,y1)-(x2,y2) Two diagonally opposite corner points. @rectAddr& Long integer expression or pointer variable which points to an 8-byte struct such as a Rect type. |
| type | any of the many types listed in the following text. |

#### New Things To Keep In Mind

On button creation, default values supplied for missing parameters (if any) are:
| state | _activeBtn |
| value | 1 |
| min | 0 |
| max | 1 |
| title$ | null string |
You can hide the control with either button -1 or appearance button -1 and you can deactivate the control with either button 1, _grayBtn or appearance button 1, _grayBtn. Buttons are commonly hidden and revealed as tab panes are brought into or removed from view. The same is true of panes that are changed in response to items such as group pop-up placards. To read an appearance button's value, use either x = button( id ) or x = button( id, _FBGetCtlRawValue )

#### Summary of Appearance Helpers

The following utility routines will help access information regarding the new appearance buttons:
actualSize = fn ButtonDataSize( btnID, part, tagName ) def GetButtonData( btnID, part, tagName, maxSize,¬ theData, actualSize ) def SetButtonTextString( btnID, theString ) theString = fn ButtonTextString$( btnID ) def SetButtonFocus( btnID ) def GetButtonTextSelection( btnID, selStart, selEnd ) def SetButtonTextSelection( btnID, selStart, selEnd )

#### Button Types

The Appearance Manager introduces many new control definitions. While it is not our intention to completely document all of Apple's new buttons, a few possible types are shown below with examples on how each might be implemented.

#### Push Buttons

Since the Appearance Manager works in both System 9 and OS X, you will see major differences in how each control is presented. Common push buttons are shown below in both versions.
| <img src="a/appearancebutton01.gif" alt="appearancebuttonhtm01" height="496" width="328" border="0"> | <img src="a/appearancebutton02.gif" alt="appearancebuttonhtm02" height="473" width="312" border="0"> |
| Push buttons in OS X | Push buttons in System 9 |
So that you may see how each button was displayed, the following code shows that source used to generate the displays.
Not all possible push buttons (and their variations) are shown here. For example, the control that displays an arrow to indicate the presence of a menu was built with a small bevel. It would have been created with a large bevel by using _kControlBevelButtonLargeBevelProc + _kControlBevelButtonMenuOnRight
Other button types that you may wish to investigate are:

#### Using Buttons to Group or Separate

FB buttons (which are Control Manager controls) can be grouped together, placed in placards or separated by lines. The following example creates buttons on a plain white background so that you may more easily see the drawing that is implemented by the control definition. We begin with the source code statements used to create the buttons.
| <img src="a/appearancebutton03.gif" alt="appearancebuttonhtm03" height="435" width="346" border="0"> | <img src="a/appearancebutton04.gif" alt="appearancebuttonhtm04" height="429" width="349" border="0"> |
| Groups and Separators in OS X | Groups and Separators in System 9 |

#### Embedding Buttons

Part of the strength of Appearance Manager buttons is that one button may be embedded in another. By disabling or hiding the parent button (called a super control), all embedded controls would automatically be disabled or hidden. Each window has a primary control known as a root control. The following example builds a window with a parent radio group button. Inside of that parent are three radio buttons. We can determine which of the three buttons has been selected by getting the value (via the button function) of the parent button.
| dim r as Rect dim pR as Rect dim h as handle dim bRef as long dim err as OSErr // setup _btnHt = 20 _btnWd = 80 _btnMargin = 8 bRef = 1 | <img src="a/appearancebutton05.gif" alt="appearancebuttonhtm05" height="152" width="103" border="0"> |

#### Check Boxes

Other than the obvious differences in physical appearance, check boxes generally follow the same guidelines as they have for many years. One notable exception to this rule is the ability to create a mixed check box. This box contains a dash instead of a check mark to show that part, but not all, of the current selection has a specific feature. This adds a new possible maximum value of 2 (_kControlCheckBoxMixedValue = 2) to the control's range.
Possible check box values now include:
_kControlCheckBoxUncheckedValue _kControlCheckBoxCheckedValue _kControlCheckBoxMixedValue
* <img src="a/appearancebutton06.gif" alt="appearancebuttonhtm04" height="136" width="207" border="0">
* Check Boxes
The buttons in the screen shot above were created using the following lines of code:
Note: You cannot use button bRef, state to tick and untick group buttons of type _kControlGroupBoxCheckBoxProc and _kControlGroupBoxSecondaryCheckBoxProc. Use appearance button bRef,,state-1 instead. (button bRef,0 and button bRef,1 will however inactivate and activate the button respectively).

#### Time and Date Buttons

In addition to more common controls, the Appearance Manager can create buttons that manage dates and times. Special data structures are maintained to access the information from these controls, but by following a few simple examples, you can quickly master these skills.
The enhanced button function is useful for extracting complex data from controls. Two specific items come in to play:
Referencing either of these functions will fill a global date/time record named gFBControlLongDate and another named gFBControlSeconds. The variable named gFBControlSeconds is a signed 64 bit variable which may be saved in a file or used in any variable where compressed storage is required.
The format for gFBControlLongDate is that of a LongDateRec which follows the layout of the structure below:
After calling the button function to examine the contents of a control, you may extract portions of the date/time as follows:
Another variable is maintained that holds the text for a specific date/time control. The contents of gFBControlText (a Pascal string) are determined by the second button function parameter. When _FBGetControlDate is used, it is the control's date. When _FBGetControlTime is used, it is the control's time.
* <img src="a/appearancebutton07.gif" alt="" height="283" width="442" border="0">
* Date/Time Buttons
In addition to setting specific types when creating a date/time control, you must set an initial value of one of the following:
The specific statements used to create the Time/Date example follow:
To extract and display the contents of a control, the following statements were created:

#### Wait States

The Appearance Manager provides several methods for telling the user that your application is busy with a task. These include chasing arrows, and finite and indeterminate progress bars.
* <img src="a/appearancebutton10.gif" alt="IMAGE imgs/appearancebutton.htm15.gif" height="144" width="120">
* Wait States
The chasing arrows control is easy to create and is self maintaining. Each time your program scans for events, the arrows are animated. The following statement creates a chasing arrows control:
Progress bars are also easy to create, but you need to keep a couple of things in mind. First, the progress bar operates in a range of -32,768 to +32,767. If your task involves a greater number of steps, you will have to calculate a ratio to keep things within range. Second, the progress bar is updated by your program. This is as easy as setting a new value for the button, but it is code that you must write.
The minimum and maximum values for the control become the minimum and maximum values for the progress bar. The initial and current value show the current rate of progress. In the example above, the button was created using the following source:
The minimum value was zero; maximum was 100. At the time of creation, the control value was 50, so the indicator shows colorization half way across the bar. If we wanted to indicate that the next step had been completed, we would use the following code:
Indeterminate progress bars are more complex. After the button is created, you must set the control's internal data to a new value. The following code shows how:

#### Range Selectors (Sliders and Arrows)

<img src="a/appearancebutton08.gif" alt="appearancebuttonhtm02" height="349" width="146" border="0">There are many variations of the slider. Each begins with the simple type constant of _kControlSliderProc. Additional parameters are added to this constant to add features to the control. The following constants are available for slider variations:
To create a slider that uses an upward pointing indicator and has tickmarks, the following type would be used:
Vertical sliders are created by building the button with a vertical dimension that is greater than the horizontal dimension. The control definition handles the new orientation automatically.
Range Selectors Sliders and Little Arrows
The following source lines show how this display was created:
When sliders are created, the number of tick marks is set by the initial value of the control. After the control is created, the value is reset to the control minimum. Sliders range from a minimum value of -32,768 to a maximum of +32,767. The number of tick marks is something that you need to determine by balancing the size of the control against the range of the control's minimum/maximum value.
The little arrows (shown in the screen shot above) are used to increment and decrement a related visual counter (usually an edit field with a specific range of numbers). The current version of the OS X control definition is intolerant of variations in the value used for the height of this type of control. Our tests show that it must be exactly 22 pixels tall. Other values offset the arrows inside of the beveled area or, in more extreme cases, can place the arrows entirely outside of the beveled area.

#### Pop-Up Menus

There are two distinct types of pop-up menus: beveled, and standard. Both are valid types and the particular use of one over the other is something that should be guided by your individual application and by Apple's Human Interface Guidelines. Beveled buttons are created as follows:
When bevel-button menus are created, the initial value for the control is the resource ID number of the menu. Three specific button function commands may be used to extract information from the control.
* <img src="a/appearancebutton11.gif" alt="" height="237" width="283">
* Pop-Up Menu Buttons
Standard pop-up buttons follow slightly different syntax. When creating, the minimum value specifies the menu resource ID and the maximum value is the width of the title for the menu. Passing in a menu ID of -12345 causes the popup not to try and get the menu from a resource. Instead, you can build the menu and later stuff the menuhandle field in the popup data information (using def SetButtonData( id&, _kControlMenuPart, _kControlPopupButtonMenuHandleTag, sizeof( handle ), @yourMenuHndl )). You can pass -1 in the max parameter to have the control calculate the width of the title on its own instead of guessing and then tweaking to get it right. It adds the appropriate amount of space between the title and the popup. A maximum value of zero means, "Don't show the title."
After creation you might need to change the value, minimum and maximum to the correct settings for your pop-up menu with:
The standard pop-up button menu in the above illustration was created with the following code:
A single button function provides access to the menu handle. Remember: standard and beveled pop-up menus do not use the same button function constants.
You can retrieve the current pop-up menu item with:

#### List Boxes

Lists generally use an auxiliary resource to define their format. The resource type used is 'ldes' and a definition for it can be created using Resourcerer 2.4 or later or by creating a template in any resource editor. You may also format a handle to match the _"ldes" record and save that handle as a resource. The resource ID for the ldes is passed in the 'value' parameter when creating the control. You may pass zero in value which would tell the List Box control to not use a resource. The list will be created with default values, and will use the standard LDEF (0). You can change the list by getting the list handle. You can set the LDEF by using the tag below (_kControlListBoxLDEFTag) in conjunction with def SetButtonData.
A list box resource is defined as follows:
The following example creates a list box from a resource with an ID of 256. Then it fills the list with item text.
To simplify this example, Resourcerer was used to create the list box resource.
* <img src="a/appearancebutton12.gif" alt="IMAGE imgs/appearancebutton.htm18.gif" height="282" width="329">
* Creating an ldes Resource
* <img src="a/appearancebutton09.gif" alt="" height="148" width="166" border="0">
* List Box

#### Tab Buttons

Tab buttons will require more work than other controls. This stems from the fact that tabs are really several controls that act in unison. First is the main tab control. When this is created you specify the number of tabs that will be present by setting the max value of the control. It is generally better to create the tab button invisibly (by using a negative button reference number) then show it by issuing a button statement with the positive version of the reference number.
After the initial shell is built for the tab, you must set the title for each tab using def SetButtonData. Then a user pane is inserted for each tab. These are embedded in the tab shell using def EmbedButton. Buttons that will reside in each user pane are created and embedded in the user pane.
When a dialog event is encountered, the value of the tab shell button corresponds to the position of the clicked tab in the tab list. Your program must loop through each user pane and show or hide them so that the display matches the clicked tab.
Study the following example to see how a working tab button is created. Be sure to note the simple dialog handler that maintains the buttons.
* <img src="a/appearancebutton13.gif" alt="" height="233" width="312" border="0">
* Tab Buttons
There are many styles of tab buttons:
This example uses _kControlTabSmallProc, but you should experiment with other types to see the results.

### Notes

No special notes.

### See Also

button&; button function; button close; scroll button; dialog function; def EmbedButton; def SetButtonData
Language Reference