TBooleanControl is an abstract base class deriving from TSimpleView, MMouseEventHandler, MControl, and MDelegatingBooleanControl.
TBooleanControls are views that present a label and a Boolean state to the user. The Boolean state is usually represented by some sort of graphic (known as the graphic label), where the graphic has a normal look and a selected look. The graphic label and the other label are arranged in relation to one another according to the MControl::ELayout setting.
Boolean controls have three possible states: unknown, false, and true. When first created, they are initialized to the unknown state.
This class creates a TBooleanInteractor if the state is enabled and the control is clicked on by a pointing device. This class should be derived from to implement a concrete look.
Instantiation:
Abstract base class; do not allocate.
Deriving Classes:
Classes deriving from TBooleanControl must implement CreateGraphicLabel and GetDefaultGraphicSize, but they do not have to provide a graphic label. Classes deriving from TBooleanControl may wish to override GetGap, CreateInteractor, HandleStateChanged, Layout, GetLayout, GetGraphicSize, and GetGraphicLabel.
Sets this control to a fixed size. When a control is set to a fixed size it will remain at the specified size, regardless of any changes to other parameters such as the label and the graphic size.
Calling Context:
You can call this function directly.
Parameters:
const TGPoint & size -The new fixed size for this control. The x-component indicates the width of the graphic label, and the y-component indicates the height.
Return Value:
None.
Exceptions:
Throws no exceptions, passes all exceptions through.
Concurrency:
Not multithread safe.
Other Considerations:
This function calls SetAllocatedArea to establish the fixed size of the control. Use SetAutoResize to undo the affect of SetFixedSize and allow the control resize itself to fit its label and graphic label.
Resizes this control to the minimum size required to display its label and graphic label, and allows it to be automatically resized in the future.
Calling Context:
You can call this function directly.
Parameters:
Takes no parameters.
Return Value:
None.
Exceptions:
Throws no exceptions, passes all exceptions through.
Concurrency:
Not multithread safe.
Other Considerations:
This function calls SetAllocatedArea to set the control to its minimum size. This function is the converse to SetFixedSize which keeps the size of the control fixed to a specified width and height.
Sets the desired size of the graphic label and marks the layout as invalid.
Calling Context:
You can call this function directly.
Parameters:
const TGPoint & size -The new size for the graphic label. The x-component indicates the width of the graphic label, and the y-component indicates the height.
Return Value:
None.
Exceptions:
Throws no exceptions, passes all exceptions through.
Concurrency:
Not multithread safe.
Other Considerations:
Subsequent calls to ForceRedraw will update the layout and, if IsFixedSize returns false, the bounds of the control.
Returns the size of the graphic label. If SetGraphicSize has not been called, this function returns a default size specified by the TBooleanControl derived class.
Calling Context:
The framework (Layout) calls this function; you may call it yourself, also, if you have a special need for it.
Parameters:
Takes no parameters.
Return Value:
Returns a TGPoint containing the current size of the graphic label. The x-component indicates the width of the graphic label, and the y-component indicates the height.
Exceptions:
Throws no exceptions, passes all exceptions through.
Returns the gap between the graphic label and the label. Classes deriving from TBooleanControl override this function if they want to change the default of 5 units.
Calling Context:
The framework (Layout) calls this function.
Parameters:
Takes no parameters.
Return Value:
Returns the current gap between the graphic label and the label.
Exceptions:
Throws no exceptions, passes all exceptions through.
Receives mouse-down events that occur inside the control and starts an interactor on the control (using CreateInteractor). Classes deriving from TBooleanControl can override this function to implement specific mouse-down handling.
Calling Context:
Called by the Input System framework; you do not need to call it directly yourself.
Parameters:
TMouseDownEvent & mouseEvent -The event that caused this function to be called.
Return Value:
Returns true if this control handled the mouse-down event, false otherwise.
Exceptions:
Throws no exceptions, passes all exceptions through.
Creates an interactor for interacting on the control. Classes deriving from TBooleanControl can override this function to return different interactors.
Calling Context:
The framework calls this function when a mouse-down event is received. You do not need to call it directly yourself.
Parameters:
const TGPoint & pt -The location where the mouse-down event occurred.
Return Value:
Returns a TInteractor object or an object that inherits from TInteractor. TBooleanControl's implementation of this function returns a TBooleanControlInteractor which should be adequate for most bool controls.
Exceptions:
Throws no exceptions, passes all exceptions through.
Handles notification that the state object's state has changed. This function updates this control with the new state and calls ForceRedraw.
Calling Context:
This function is called by the framework (from StateChanged) when a notification is received from the state object that the state has changed. You never need to call it directly yourself.
Parameters:
Takes no parameters.
Return Value:
None.
Exceptions:
Throws no exceptions, passes all exceptions through.
Redraws the control, showing the control pressed feedback. The control is pressed when the user holds the mouse button down over it.
Calling Context:
The framework calls this function for you when the user interacts with the control via pointing device or keyboard equivalent. You may also call this function directly yourself.
Parameters:
bool -The flag indicating whether to set this control to pressed or unpressed. true sets the control to pressed; false sets it to unpressed.
Return Value:
None.
Exceptions:
Throws no exceptions, passes all exceptions through.
Sets the state of this control's state object by calling SetBooleanState on its state object. This function redraws the control to indicate the new state.
Calling Context:
Called at the end of a user interaction. You can also call this function directly.
Parameters:
MBooleanControlState :: EBooleanState newState -The new state for this control's state object.
Return Value:
None.
Exceptions:
Throws no exceptions, passes all exceptions through.
Lays out this control. If the control is not fixed size, this function calls SetAllocatedArea to set the new preferred size.
Calculates the layout given the actual bounds of the control. This layout is sensitive to the last layout parameter given to the MControl::SetControlLayout. (MControl is a parent of TBooleanControl). So for example, a kLeftToRight layout results in the graphic label on the left and the other label on the right. After controlling the layout of the two labels relative to each other, the MControl::ELayout setting then controls the layout of the two as a combined unit inside the actualBounds, if the actualBounds is not NIL. By performing this layout in TBooleanControl, all classes deriving from TBooleanControl can share this logic by calling GetLayout.
Calling Context:
The framework calls this function for you, but you may call it yourself, if you have a special need for it.
Called from ForceRedraw when the layout needs recalculating.
Called by GetPreferredSize and by the first Layout function.
Parameters:
Takes no parameters.
const TGRect & actualBounds -The bounds within which to layout the control. A zero bounds will assume a preferred size layout.
TGRect & graphicBounds -The location at which to put the graphic label.
TGRect & labelBounds -The location at which to put the label.
Return Value:
None.
Exceptions:
Throws no exceptions, passes all exceptions through.
Concurrency:
Not multithread safe.
Other Considerations:
IsFixedSize reports whether the control is fixed size.
The framework definition of this function is that it creates and returns the graphic label that is used as part of the control's presentation. TBooleanControl supplies no default implementation of this function; deriving classes which you instantiate must implement this function. Implementations are allowed to return NIL sometimes or always.
Calling Context:
The framework calls this function once when the graphic is first needed.
Parameters:
Takes no parameters.
Return Value:
Returns a graphic label.
Exceptions:
Throws no exceptions, passes all exceptions through.
Concurrency:
Not multithread safe.
Other Considerations:
This function is a pure virtual function and must be overridden by classes deriving from TBooleanControl before the derived classes get instantiated into objects.
Reports the default size of the control's display. Since this is a pure virtual function, you must override it to return the default size.
Calling Context:
The framework calls this function.
Parameters:
TGPoint & size -This function fills in the default size for the control. The x-component of the point is the width, and the y-component of the point is the height.
Return Value:
None.
Exceptions:
Throws no exceptions, passes all exceptions through.
Programatically select the control as if the user clicked on the control with a pointing device. This can be used to select a control through a keyboard based interface.
Calling Context:
This member function is currently not used by the framework -but it maybe used later when the framework supports a keyboard interface.
Parameters:
Takes no parameters.
Return Value:
None.
Exceptions:
Throws no exceptions, passes all exceptions through.
Concurrency:
Not multithread safe.
Other Considerations:
This member function simulates a mouse click over the control which results in SetPressed(true), SetBooleanState(xxxx), then SetPressed(false), were xxxx is the toggled state.
Reports whether any drawing done by this control needs view system assistance to ensure that the drawing is clipped to the area of the control. Objects that return false (the supplied default) will get their drawing performed faster, but without checking to prevent them from over-drawing things outside themselves.
The default allocation constructor, supplied by TBooleanControl, initializes objects to report that they do not need clipping done by the view system.
Calling Context:
The framework calls this function when drawing the control.
Parameters:
Takes no parameters.
Return Value:
Returns true if the control ever draws outside its bounds.
Exceptions:
Throws no exceptions, passes all exceptions through.
Sets the orientation of the control's graphic elements with respect to each other (right-to-left, left-to-right, top-to-bottom, or bottom-to-top). If that newly set orientation is different from the previously determined one, recalculates the positions of the graphic elements and posts an indication of the need to redraw the control.
Calling Context:
You can call this function directly.
Parameters:
MControl :: ELayout layout -The orientation of the control's graphic elements with respect to each other (right-to-left, left-to-right, top-to-bottom, or bottom-to-top)
Return Value:
None.
Exceptions:
Throws no exceptions, passes all exceptions through.
Concurrency:
Not multithread safe.
Other Considerations:
This function overrides MControl's SetControlLayout function.
Reports whether the control is visible or invisible when inside the viewable area of the display.
Calling Context:
You can call this function directly.
Parameters:
Takes no parameters.
Return Value:
Returns true if the control is visible, otherwise false.
Exceptions:
Throws no exceptions, passes all exceptions through.
Concurrency:
Not multithread safe.
Other Considerations:
Because two base classes--MControl and TView--have their own GetVisibility functions, this function removes any ambiguity as to which will report a TBooleanControl's visibility; it delegates visibility reporting to TView.
Enables the control. In the process, this function enables the control's label and its graphic label if it has them, and then posts a flag showing that its display needs to be redrawn.
Calling Context:
You can call this function directly. The framework calls it to enable controls, also.
Parameters:
bool enabled -true enables the control, false disables it.
Return Value:
None.
Exceptions:
Throws no exceptions, passes all exceptions through.
Reports the preferred bounds of the control rather than the current allocated area, so that the control can grow and shrink when adopted into a TLayoutView derived class.
Calling Context:
You can call this function directly. The framework calls it also.
Parameters:
TGArea & area -Filled by this function with the bounds of the control.
Return Value:
None.
Exceptions:
Throws no exceptions, passes all exceptions through.
Concurrency:
Not multithread safe.
Other Considerations:
If the control has a fixed size, this function reports it, otherwise it reports the preferred size.