Main Page   Class Hierarchy   Compound List   File List   Compound Members  

csComponent Class Reference

Graphics system component: a menu, window etc.<. More...

#include <cscomp.h>

Inheritance diagram for csComponent:

csApp csButton csDialog csGrid csGridCell csGridView csHint csInputLine csKeyboardAccelerator csListBox csListBoxItem csMenu csMenuItem csNotebook csScrollBar csSplitter csStatic csTimer csTitleBar csTreeBox csTreeItem csWindow List of all members.

Public Methods

 csComponent (csComponent *iParent)
 Create a component and insert it into parent's child list if parent != NULL.

virtual ~csComponent ()
 Destroy component and remove it from parent't child list.

virtual void Insert (csComponent *comp)
 Insert a child component.

virtual void Delete (csComponent *comp)
 Delete a child component.

void DeleteAll ()
 Delete all children components.

void InsertClipChild (csComponent *clipchild)
 Insert a 'clip child'.

void DeleteClipChild (csComponent *clipchild)
 Remove a 'clip child'.

csComponent* GetClipParent ()
 Return the 'clip parent' component.

virtual bool SetFocused (csComponent *comp)
 Focus a child component.

csComponent* GetFocused ()
 Get the focused child window.

bool Select ()
 Select (focus) this component and return true if successful.

virtual csComponent* NextChild (csComponent *start=NULL, bool disabled=false)
 Return next visible selectable child window after 'start'.

virtual csComponent* PrevChild (csComponent *start=NULL, bool disabled=false)
 Return previous visible selectable child window before 'start'.

virtual csComponent* NextControl (csComponent *start=NULL)
 Return next control after 'start', looping through groups.

virtual csComponent* PrevControl (csComponent *start=NULL)
 Return previous control before 'start', looping through groups.

virtual csComponent* NextGroup (csComponent *start=NULL)
 Return control in next group after 'start'.

virtual csComponent* PrevGroup (csComponent *start=NULL)
 Return control in previous group before 'start'.

bool FixFocused ()
 Fix the focused child if it is not selectable (find another).

bool SetZorder (csComponent *comp, csComponent *below)
 Change Z-order of a child component above 'below' (can be NULL for lowest Z-order) neightbour.

csComponent* GetTop ()
 Get the top Z-order child window.

void SetPalette (int *iPalette, int iPaletteSize)
 Set component logical palette.<. More...

void SetPalette (int iPaletteID)
 Same, but accepts the index into cswsPalette[] array.

void ResetPalette ()
 Reset the palette of the component to the palette it had at startup.

void SetColor (int Index, int Color)
 Set a color value in palette (makes a copy of *palette if not already).

int GetColor (int Index)
 Get a color from logical palette.

virtual void SetText (const char *iText)
 Most components have a text string field. More...

virtual void GetText (char *oText, int iTextSize) const
 Query component text.

virtual const char* GetText () const
 Same, but you cannot change returned value.

csComponent* ForEach (bool(*func)(csComponent *child, void *param), void *param=NULL, bool Zorder=false)
 For each child component call a function with a optional arg Function returns the first child on which func returnes 'true' Function can scan from top-Z child (Zorder == true) or from focused child (Zorder == false).

csComponent* GetChild (int find_id) const
 Find a child component by its ID.

void SetApp (csApp *newapp)
 Set the application for this object and all its children.

virtual bool HandleEvent (iEvent &Event)
 Handle a event and return true if processed.

virtual bool PreHandleEvent (iEvent &Event)
 Handle a event BEFORE all others. More...

virtual bool PostHandleEvent (iEvent &Event)
 Handle a event if nobody eaten it.

void* SendCommand (int CommandCode, void *Info=NULL)
 Send a command to this window and returns the Info field of iEvent object.

void* SendBroadcast (int CommandCode, void *Info=NULL)
 Send a broadcast to this window and returns the Info field of iEvent object.

csComponent* GetDefault ()
 Find the 'default' child.

void Redraw ()
 Redraw the component if it has a dirty area.

virtual void Draw ()
 Draw the component (only dirty rectangle should be redrawn).

virtual void Show (bool focused=false)
 Show the component (and activate it if focused == true).

virtual void Hide ()
 Hide the component.

virtual bool SetRect (int xmin, int ymin, int xmax, int ymax)
 Set component rectangle to given. Return false if not changed.

bool SetRect (csRect &rect)
 Same, but with csRect argument.

bool SetDragRect (int xmin, int ymin, int xmax, int ymax)
 Calls SetRect after calling FixPosition and FixSize (used when dragging).

void SetPos (int x, int y)
 Set component position to given X and Y.

void SetSize (int w, int h)
 Set component size to given Width and Height.

void Center (bool iHoriz=true, bool iVert=true)
 Center window inside parent.

virtual bool Maximize ()
 Maximize window if it is not already and if DragStyle has CS_DRAG_SIZEABLE.

virtual bool Restore ()
 Restore window if it is maximized and if DragStyle has CS_DRAG_SIZEABLE.

void Invalidate (csRect &area, bool IncludeChildren=false, csComponent *below=NULL)
 Invalidate a area of component (force a redraw of this area). More...

void Invalidate (int xmin, int ymin, int xmax, int ymax, bool IncludeChildren=false, csComponent *below=NULL)
 Same, but with coordinates instead of rectangle.

void Invalidate (bool IncludeChildren=false, csComponent *below=NULL)
 Same, but invalidates entire component (and possibly all children).

virtual void SetState (int mask, bool enable)
 Set/clear given component state flags.

int GetState (int mask)
 Return component state flags.

void SetDragStyle (int iDragStyle)
 Set drag style flags.

int GetDragStyle ()
 Query drag style flags.

void SetResizeMode (int iResizeMode)
 Set resize mode flags.

int GetResizeMode ()
 Query resize mode flags.

void LocalToGlobal (int &x, int &y)
 Convert a pair of X,Y coordinates from local to global coordinate system.

void GlobalToLocal (int &x, int &y)
 Convert a pair of X,Y coordinates from global to local coordinate system.

void OtherToThis (csComponent *from, int &x, int &y)
 Convert a X,Y pair from coordinate system of another window to this one. More...

void Drag (int x, int y, int DragMode)
 Drag a window with mouse located at (x,y) window-local coordinates.

void SetMouse (csMouseCursorID Cursor)
 Set mouse cursor pointer.

virtual void Close ()
 Destroy this component<. More...

csComponent* GetChildAt (int x, int y, bool(*func)(csComponent *, void *)=NULL, void *data=NULL)
 Get the (possibly child) component that is topmost at given x,y location. More...

void SetSizingCursor (int dragtype)
 Set mouse cursor to one of sizing cursors depending on drag mode flags (dragtype should be any combination of CS_DRAG_XXX bits).

bool GetMousePosition (int &x, int &y)
 Query current mouse location (returns true if mouse is inside this component).

bool HandleDragEvent (iEvent &Event, int BorderW, int BorderH)
 Handle a mouse drag event. More...

virtual void FixPosition (int &newX, int &newY)
 Fix new window position before assigning to component.

virtual void FixSize (int &newW, int &newH)
 Fix new window size before assigning to component.

virtual void SuggestSize (int &w, int &h)
 Return the recommended minimal size of component.

virtual void SetSuggestedSize (int dw, int dh)
 Set the size of component to minimal possible plus delta.

void FindMaxFreeRect (csRect &area)
 Find the maximal rectangle uncovered by child windows.

virtual char* GetSkinName ()
 Get the name of the skip slice for this component (if not NULL).

virtual csSkinGetSkin ()
 Get the closest in window hierarchy skin object.

void SetClipRect (int xmin, int ymin, int xmax, int ymax)
 Set clipping rectangle. More...

void SetClipRect ()
 Disable clipping.

void SetFont (iFont *iNewFont, int iSize=-1)
 Set font for this component and the size (-1 - leave as-is, 0 - from parent).

virtual void GetFont (iFont *&oFont, int &oFontSize)
 Query current text font and his size for this component.

void Box (int xmin, int ymin, int xmax, int ymax, int colindx)
 Draw a box.

void Line (float x1, float y1, float x2, float y2, int colindx)
 Draw a line.

void Pixel (int x, int y, int colindx)
 Draw a pixel.

void Text (int x, int y, int fgindx, int bgindx, const char *s)
 Draw a text string: if bg < 0 background is not drawn.

void Pixmap (csPixmap *s2d, int x, int y, int w, int h, uint8 Alpha=0)
 Draw a (scaled) 2D sprite.

void Pixmap (csPixmap *s2d, int x, int y, uint8 Alpha=0)
 Draw a (non-scaled) 2D sprite.

void Pixmap (csPixmap *s2d, int x, int y, int w, int h, int orgx, int orgy, uint8 Alpha=0)
 Draw a (tiled) pixmap (orgy stands for "origin y", not what you though of - shame!).

void Texture (iTextureHandle *tex, int x, int y, int w, int h, int orgx, int orgy, uint8 Alpha=0)
 Draw a (possibly tiled) texture, possibly semi-transparent.

int GetTextSize (const char *text, int *oHeight=NULL)
 Return the width of given text using current font (and possibly height).

int GetTextChars (const char *text, int iWidth)
 Return how many letters from given string fits in this number of pixels.

void Rect3D (int xmin, int ymin, int xmax, int ymax, int darkindx, int lightindx)
 Draw a 3D-looking thin rectangle.

void ObliqueRect3D (int xmin, int ymin, int xmax, int ymax, int cornersize, int darkindx, int lightindx)
 Draw a 3D rectangle with two oblique corners (used for buttons, for example).

void Clear (int colindx)
 Clear the entire component with given color.

void ClearZbuffer (int xmin, int ymin, int xmax, int ymax)
 Clear the Z-buffer in the given rectangle.

void ClearZbuffer ()
 Clear the Z-buffer in the area covered by this component.

void Polygon3D (G3DPolygonDPFX &poly, uint mode)
 Draw a 3D polygon.

void DrawUnderline (int iX, int iY, const char *iText, int iUnderlinePos, int iColor)
 -------------------------------------- Utility drawing functions ---------- Draw a underline under iText drawn at iX,iY with iColor.

Public Attributes

csComponent* focused
 The focused child window.

csComponent* top
 The top-Z child window.

csComponent* next
 Next and previous neightbours.

csComponent * prev
 Next and previous neightbours.

csComponent* parent
 Parent component or NULL.

 Top-level application object.

 Component skin slice.

csSome* skindata
 Abstract pointer for internal use by skin slice.

unsigned int id
 Component ID, unique within its parrent's child ring.

csRect bound
 Component size/position rectangle.

Protected Methods

void Clip (cswsRectVector &rect, csComponent *last, bool forchild=false)
 Clip a set of rectangles so that they will contain only rectangles uncovered by other windows. More...

void ClipChild (cswsRectVector &rect, csComponent *child)
 Clip the rectangle set against given child.

void FastClip (cswsRectVector &rect)
 Perform fast clipping by using the pre-cached visible region initialized at start of Redraw(). More...

bool CheckHotKey (iEvent &iEvent, char iHotKey)
 Check if the keyboard event fits given hot key.

bool ApplySkin (csSkin *Skin)
 Apply a skin only to this component: returns true on success.

void CheckDirtyTD (csRect &ioR)
 Perform a check of this component and all dirty children' dirty areas: if child component is transparent, unify his dirty area with this component's dirty area. More...

void CheckDirtyBU (csRect &ioR)
 Same as CheckDirtyTD but the check is performed in the inverse direction - from bottom up (`BU'). More...

Protected Attributes

int state
 Object state flags (see CSS_XXX flags).

csRect dirty
 Rectangle that should be redrawn.

csRect clip
 Clipping rectangle (if not empty).

int* palette
 Component palette and palette length.

int palettesize
 Component palette and palette length.

int* originalpalette
 Original component palette.

csRect OrgBound
 Original bound when window is maximized.

char DragStyle
 Window drag style (see CS_DRAG_XXX above).

char ResizeMode
 What to do when parent size changes (see CS_LOCK_XXX flags).

csComponent* clipparent
 Component against which this component is clipped


char* text
 Most components contain a text string. Unify the interface.

 Current font (or NULL if should use parent font).

int FontSize
 Current font size.

csVector clipchildren
 An array of 'clip children', i.e. components which are clipped inside our bounds.

Static Protected Methods

void PrepareLabel (const char *iLabel, char *&oLabel, int &oUnderlinePos)
 Prepare a label. More...

int WordLeft (const char *iText, int StartPos)
 Utility functions: return position one word left from StartPos.

int WordRight (const char *iText, int StartPos)
 Return position one word right from StartPos.

Static Protected Attributes

int dragX
 Used on drag operations.

int dragY
 Used on drag operations.

int dragMode
 Used on drag operations.

 The component bound before drag started.

cswsRectVector* visregion
 This field is used to cache current clipping region during every Redraw().

Detailed Description

Graphics system component: a menu, window etc.<.

p> This is an abstract base class: all windowing system classes should be subclassed from csComponent. Each component can have a number of child components. Child components are chained together in a ring list; the only case when a NULL can be encountered in this list is when component has no children. When a component has at least one child and if you traverse the child list you should take care to avoid looping forever through them.

A csComponent object is a rectangle area of screen which can contain absolutely any content. The object is responsible for filling all pixels within that rectangle, i.e. underlying windows will never touch other window's area. If the component's `state' field has the CSS_TRANSPARENT bit set, the component can have partially transparent parts (those are filled by underlying component(s)). In this case the underlying components are painted before this component, and then anything you draw inside the Draw() method is overlayed onto parent component's image.

Member Function Documentation

void csComponent::CheckDirtyBU ( csRect & ioR ) [protected]

Same as CheckDirtyTD but the check is performed in the inverse direction - from bottom up (`BU').

This routine checks if the transparent child components are covered by this component's dirty area; if so, the respective areas of child windows are marked as dirty as well.

void csComponent::CheckDirtyTD ( csRect & ioR ) [protected]

Perform a check of this component and all dirty children' dirty areas: if child component is transparent, unify his dirty area with this component's dirty area.

You will never need to call this function manually; this is done automatically. The `TD' prefix stands for `top-doen', that is the Z-order in which the check is performed.

void csComponent::Clip ( cswsRectVector & rect,
csComponent * last,
bool forchild = false ) [protected]

Clip a set of rectangles so that they will contain only rectangles uncovered by other windows.

Initial rectangles are in local coordinates, final rectangles are in global coordinates.

void csComponent::Close ( ) [virtual]

Destroy this component<.

p> You should not call any methods or use any variables after this! When this function returns, the object is already destroyed.

void csComponent::FastClip ( cswsRectVector & rect ) [protected]

Perform fast clipping by using the pre-cached visible region initialized at start of Redraw().

This has the side effect that any drawing operation that happens outside the Draw() method is effectively clipped away.

csComponent * csComponent::GetChildAt ( int x,
int y,
bool(* func)(csComponent *, void *) = NULL,
void * data = NULL )

Get the (possibly child) component that is topmost at given x,y location.

This is useful, for example, to get the component under mouse cursor. You can provide a test function that will be called for "transparent" childs; if the child has the CSS_TRANSPARENT flag set, this routine will be called to determine whenever we should go further below this child. If the routine is NULL, it will stop at the first transparent child. If the routine returns true, GetChildAt() will return given child component.

bool csComponent::HandleDragEvent ( iEvent & Event,
int BorderW,
int BorderH )

Handle a mouse drag event.

Check if mouse cursor is within BorderW/BorderH distance from window border; for mouse move events just sets the corresponding mouse shape (if DragMode has CS_DRAG_SIZEABLE bit set). If event is a mouse down event and mouse cursor falls within that distance from window border either resize or move window mode is entered. The function returns "true" if event has been processed, and false if it can be processed by other handlers. This function is handy to call from event handlers of all windows that can be resized and/or moved, example:

   switch (Event.Type)
     case csevMouseDown:
     case csevMouseMove:
       if (HandleDragEvent (Event, BorderWidth, BorderHeight))
         return true;
       return csComponent::HandleEvent (Event);

void csComponent::Invalidate ( csRect & area,
bool IncludeChildren = false,
csComponent * below = NULL )

Invalidate a area of component (force a redraw of this area).

If fIncludeChildren is true, all child components that covers this area of parent will be partially invalidated as well. Additionaly, if 'below' is not NULL, only the child components that are below 'below' in Z-order or CSS_TRANSPARENT components that are 'above' in Z-order will be invalidated.

void csComponent::OtherToThis ( csComponent * from,
int & x,
int & y )

Convert a X,Y pair from coordinate system of another window to this one.

This works faster than GlobalToLocal/LocalToGlobal pair in the case when this component is a N-th level parent for the 'from' component.

bool csComponent::PreHandleEvent ( iEvent & Event ) [virtual]

Handle a event BEFORE all others.

You will receive ALL events including focused events. For example, a object will receive mouse events even if object is not visible. A object should take care not to block events expected by other objects.

Reimplemented in csApp, csHint, and csMenu.

void csComponent::PrepareLabel ( const char * iLabel,
char *& oLabel,
int & oUnderlinePos ) [static, protected]

Prepare a label.

Search for '~' in iLabel, and copy text without '~' into oLabel. Former underline position is stored into oUnderlinePos. This is used by labels, menuitems, static components etc.

void csComponent::SetClipRect ( int xmin,
int ymin,
int xmax,
int ymax ) [inline]

Set clipping rectangle.

All following drawing will be clipped against given rectangle. Setting w=0 or h=0 will disable clipping (although it will be anyway performed relative to component bound).

void csComponent::SetPalette ( int * iPalette,
int iPaletteSize )

Set component logical palette.<.

p> Each component has its own logical palette. A logical palette component is a index into a global table which resides in csApp object. The table in csApp maps a color (such as cs_Color_White) to a real index into the physical palette.

It is highly desirable for components to contain in their 1st element their background color. This is sometimes used (for example by irregularily-shaped buttons).

void csComponent::SetText ( const char * iText ) [virtual]

Most components have a text string field.

For example, titlebars, buttons, input lines, static components etc etc etc. The following routines are used to access this field in a component-independent manner.

Reimplemented in csButton, csHint, csInputLine, csMenuItem, csSpinBox, csStatic, and csWindow.

The documentation for this class was generated from the following file:
Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000