The abstract base class for all components. More...
#include <CComponent.h>
Public Member Functions | |
CComponent () | |
Constructs a new component. | |
CComponent (const CComponent &c) | |
Copy constructor to throw a exception. | |
void | DispatchEvent (SKeyEvent *e) |
Dispatches an event to this component or one of its sub components. | |
void | SetCommandAction (void *obj, void(*action)(void *, CComponent *)) |
Sets the object and it's function to process a action. | |
void | PerformAction () |
Executes business function, if it is set. | |
BOOL | IsFocusOwner () |
Returns true if this Component is the focus owner. | |
BOOL | IsFocusable () |
Returns whether this Component can be focused. | |
void | SetFocusable (BOOL focusable) |
Sets the focusable state of this Component to the specified value. | |
void | TransferFocus () |
Transfers the focus to the next component. | |
void | TransferFocusBackward () |
Transfers the focus to the previous component. | |
void | TransferFocusUpCycle () |
Transfers the focus up one focus traversal cycle. | |
virtual void | OnTimer () |
This function is called in the GUI loop for making regular actions like timer actions. | |
void | Repaint () |
Repaints this component. | |
void | Redraw (CGraphics *g) |
Does default paint operations for the component. | |
virtual void | Paint (CGraphics *g) |
Paints the component. | |
void | Bordered (BOOL b) |
Sets whether showing border for this component. | |
virtual void | SetSize (INT16 width, INT16 height) |
Resizes this object so that it has width and height. | |
virtual void | SetLocation (INT16 x, INT16 y) |
Sets the location of the object relative to the parent. | |
SPoint | GetScreenPosition () |
Returns the location of the object on the screen. | |
CFont * | GetFont () |
Gets the font of this component. | |
void | SetFont (CFont *font) |
Sets the font of this component. | |
CComponent * | GetParent () |
Gets the parent of this component. | |
void | SetLayout (ILayoutManager *layout) |
Sets the layout manager for this component. | |
virtual void | Add (CComponent *component) |
Appends the specified component to the end of this component. | |
INT8 | GetComponentCount () |
Gets the number of components in this panel. | |
virtual void | Invalidate () |
Invalidates the component. | |
void | Validate () |
Validates this component and all of its subcomponents. | |
BOOL | IsValid () |
Determines whether this component is valid. | |
Protected Member Functions | |
virtual void | PreviewProcessComponentKeyEvent (SKeyEvent *e) |
Processes events occurring on this component before this event will processed by focus component. | |
virtual void | ProcessComponentKeyEvent (SKeyEvent *e) |
Processes events occurring on this component,. | |
void | PaintBorder (CGraphics *g) |
Paints the component's border, if the component is bordered. | |
void | Remove (CComponent *component) |
Removes the specified component from this component. | |
void | ValidateTree () |
Recursively descends the component tree and recomputes the layout for any subtrees marked as needing it (those marked as invalid). | |
Protected Attributes | |
INT32 | m_background |
The background color for this component. | |
INT32 | m_foreground |
The foreground color for this component. | |
BOOL | m_bordered |
Whether the component is bordered. | |
INT16 | m_x |
The x position of the component in the parent's coordinate system. | |
INT16 | m_y |
The y position of the component in the parent's coordinate system. | |
INT16 | m_sx |
The x position of the component in the screen coordinate system. | |
INT16 | m_sy |
The y position of the component in the screen coordinate system. | |
INT16 | m_width |
The width of the component. | |
INT16 | m_height |
The height of the component. | |
INT16 | m_swidth |
The clip screen width of the component. | |
INT16 | m_sheight |
The clip screen height of the component. |
The abstract base class for all components.
To use a component that inherits from CComponent
, you must place the component in a containment hierarchy whose root is a top-level component. Top-level components are inheritors of the CForm
.
SetKey
and GetKey
is not implemented. Use the pointer to a component for identification of a object.
CComponent::CComponent | ( | ) |
Constructs a new component.
Class CComponent
can be extended directly to create another component.
void CComponent::Add | ( | CComponent * | component | ) | [virtual] |
Appends the specified component to the end of this component.
Note: If a component has been added to a component that has been displayed, Validate must be called on that component to display the new component. If multiple components are being added, you can improve efficiency by calling Validate only once, after all the components have been added.
component | - the component to be added |
Reimplemented in CWindow.
void CComponent::Bordered | ( | BOOL | b | ) | [inline] |
Sets whether showing border for this component.
b | - true , if component is bordered. |
void CComponent::DispatchEvent | ( | SKeyEvent * | e | ) |
Dispatches an event to this component or one of its sub components.
Calls ProcessComponentKeyEvent
for the CComponent
.
e | - the event |
INT8 CComponent::GetComponentCount | ( | ) |
Gets the number of components in this panel.
CFont * CComponent::GetFont | ( | ) |
Gets the font of this component.
CComponent * CComponent::GetParent | ( | ) |
Gets the parent of this component.
SPoint CComponent::GetScreenPosition | ( | ) |
Returns the location of the object on the screen.
TODO can be null
if this object is not on the screen
void CComponent::Invalidate | ( | ) | [virtual] |
Invalidates the component.
The component and all parents above it are marked as needing to be laid out. This method can be called often, so it needs to execute quickly.
Reimplemented in CForm.
BOOL CComponent::IsFocusable | ( | ) |
Returns whether this Component can be focused.
true
if this Component is focusable; false
otherwise. BOOL CComponent::IsFocusOwner | ( | ) |
Returns true
if this Component
is the focus owner.
true
if this Component
is the focus owner; false
otherwise BOOL CComponent::IsValid | ( | ) |
Determines whether this component is valid.
A component is valid when it is correctly sized and positioned within its parent container and all its children are also valid.
true
if the component is valid, false
otherwise void CComponent::OnTimer | ( | ) | [virtual] |
This function is called in the GUI loop for making regular actions like timer actions.
Main GUI loop:
while( 1 ) { while( CTerminal::NextAction() ) { CTerminal::ProcessUserActions(); } CTerminal::OnTimer();// this will be call OnTimer for every Component CTerminal::Paint(); usleep( REFRESH_PERIOD_MKS ); }
void CComponent::Paint | ( | CGraphics * | g | ) | [virtual] |
Paints the component.
This forwards the paint to any components that are children of this component. If this method is reimplemented, Paint(g) of base class should be called so components are properly rendered.
g | - the specified Graphics context |
Reimplemented in CButton, CComboBox, CIPAddressBox, CLabel, CListBox, and CTextBox.
void CComponent::PaintBorder | ( | CGraphics * | g | ) | [protected] |
Paints the component's border, if the component is bordered.
g |
void CComponent::PreviewProcessComponentKeyEvent | ( | SKeyEvent * | e | ) | [protected, virtual] |
Processes events occurring on this component before this event will processed by focus component.
e | - the event |
void CComponent::ProcessComponentKeyEvent | ( | SKeyEvent * | e | ) | [protected, virtual] |
Processes events occurring on this component,.
e | - the event |
Reimplemented in CButton, CComboBox, CForm, CIPAddressBox, and CTextBox.
void CComponent::Redraw | ( | CGraphics * | g | ) |
Does default paint operations for the component.
TODO If a child component is entirely clipped by the current clipping setting in g, paint() will not be forwarded to that child.
don't call directly! only for system call.
g | - the specified Graphics context |
void CComponent::Remove | ( | CComponent * | component | ) | [protected] |
Removes the specified component from this component.
Note: If a component has been removed from a component that had been displayed, Validate must be called on that container to reflect changes. If multiple components are being removed, you can improve efficiency by calling Validate only once, after all the components have been removed.
component | - the component to be removed |
void CComponent::SetCommandAction | ( | void * | obj, | |
void(*)(void *, CComponent *) | action | |||
) |
Sets the object and it's function to process a action.
obj | - a object with a business function | |
action | - a function of a business object |
void CComponent::SetFocusable | ( | BOOL | focusable | ) |
Sets the focusable state of this Component to the specified value.
This value overrides the Component's default focusability.
focusable | indicates whether this Component is focusable |
void CComponent::SetFont | ( | CFont * | font | ) |
Sets the font of this component.
font | - The font to become this container's font. |
void CComponent::SetLayout | ( | ILayoutManager * | layout | ) |
Sets the layout manager for this component.
layout | - the specified layout manager |
void CComponent::SetLocation | ( | INT16 | x, | |
INT16 | y | |||
) | [virtual] |
Sets the location of the object relative to the parent.
Note: Validate must be called on that component for compile new layout, if ILayoutManager is defined
x | - X coordinate of the object | |
y | - Y coordinate of the object |
Reimplemented in CForm.
void CComponent::SetSize | ( | INT16 | width, | |
INT16 | height | |||
) | [virtual] |
Resizes this object so that it has width and height.
Note: Validate must be called on that component for compile new layout, if ILayoutManager is defined
width | - the new width of the object | |
height | - the new height of the object |
void CComponent::TransferFocusUpCycle | ( | ) |
Transfers the focus up one focus traversal cycle.
Typically, the focus owner is set to this Component's focus cycle root, and the current focus cycle root is set to the new focus owner's focus cycle root. If, however, this Component's focus cycle root is a Window, then the focus owner is set to the focus cycle root's default Component to focus, and the current focus cycle root is unchanged.
void CComponent::Validate | ( | ) |
Validates this component and all of its subcomponents.
The Validate method is used to cause a component to lay out its subcomponents again. It should be invoked when this container's subcomponents are modified (added to or removed from the container, or layout-related information changed) after the component has been displayed.
If this component is not valid, this method invokes the ValidateTree method and marks this component as valid. Otherwise, no action is performed.
void CComponent::ValidateTree | ( | ) | [protected] |