CrystalSpace

Public API Reference

Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

cscomp.h

Go to the documentation of this file.
00001 /*
00002     Crystal Space Windowing System: Windowing System Component interface
00003     Copyright (C) 1998,1999 by Andrew Zabolotny <bit@eltech.ru>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 #ifndef __CS_CSCOMP_H__
00021 #define __CS_CSCOMP_H__
00022 
00031 #include "csextern.h"
00032  
00033 #include "csgeom/csrect.h"
00034 #include "csutil/parray.h"
00035 #include "csutil/array.h"
00036 #include "cstool/cspixmap.h"
00037 #include "cswspal.h"
00038 #include "ivideo/graph2d.h"
00039 #include "ivideo/fontserv.h"
00040 
00041 class csApp;
00042 class csSkin;
00043 class csSkinSlice;
00044 struct iEvent;
00045 
00046 // this is where we store all the csRect for calculating visible areas and clipping in
00047 typedef csPDelArray<csRect> cswsRectVector;
00048 
00075 
00076 #define CSS_VISIBLE             0x00000001
00077 
00078 #define CSS_FOCUSED             0x00000002
00079 
00080 #define CSS_DISABLED            0x00000004
00081 
00082 #define CSS_SELECTABLE          0x00000008
00083 
00084 #define CSS_GROUP               0x00000010
00085 
00086 #define CSS_TOPSELECT           0x00000020
00087 
00088 #define CSS_TRANSPARENT         0x00000040
00089 
00090 #define CSS_MODAL               0x00000080
00091 
00092 #define CSS_MAXIMIZED           0x00000100
00093 
00094 #define CSS_DIRTY               0x00000200
00095 
00096 #define CSS_RESTART_DIRTY_CHECK 0x00000400
00097 
00136 enum
00137 {
00147   cscmdAreYouDefault = 0x80,
00157   cscmdActivate,
00161   cscmdHide,
00165   cscmdMaximize,
00169   cscmdClose,
00178   cscmdLimitMaximize,
00188   cscmdLoseFocus,
00198   cscmdReceiveFocus,
00203   cscmdOK,
00205   cscmdCancel,
00207   cscmdAbort,
00209   cscmdRetry,
00211   cscmdIgnore,
00220   cscmdColorSchemeChanged,
00233   cscmdSkinChanged,
00242   cscmdMoveClipChildren,
00246   cscmdStopModal
00247 };
00248 
00254 
00255 #define CS_DRAG_XMIN            0x01
00256 
00257 #define CS_DRAG_XMAX            0x02
00258 
00259 #define CS_DRAG_YMIN            0x04
00260 
00261 #define CS_DRAG_YMAX            0x08
00262 
00263 #define CS_DRAG_MOVEABLE        0x10
00264 
00265 #define CS_DRAG_SIZEABLE        0x20
00266 
00267 #define CS_DRAG_ALL             \
00268         (CS_DRAG_XMIN | CS_DRAG_XMAX | CS_DRAG_YMIN | CS_DRAG_YMAX)
00269 
00279 
00280 #define CS_LOCK_XMIN            0x01
00281 
00282 #define CS_LOCK_XMAX            0x02
00283 
00284 #define CS_LOCK_YMIN            0x04
00285 
00286 #define CS_LOCK_YMAX            0x08
00287 
00288 #define CS_LOCK_ALL             \
00289         (CS_LOCK_XMIN | CS_LOCK_XMAX | CS_LOCK_YMIN | CS_LOCK_YMAX)
00290 
00306 
00307 #define CS_REPOS_HORIZONTAL     0x10
00308 
00309 #define CS_REPOS_VERTICAL       0x20
00310 
00311 #define CS_REPOS_H_MASK         (CS_REPOS_HORIZONTAL | 0x3)
00312 
00313 #define CS_REPOS_V_MASK         (CS_REPOS_VERTICAL | 0xc)
00314 
00315 #define CS_REPOS_LEFT           (CS_REPOS_HORIZONTAL | 0x0)
00316 
00317 #define CS_REPOS_RIGHT          (CS_REPOS_HORIZONTAL | 0x1)
00318 
00319 #define CS_REPOS_HCENTER        (CS_REPOS_HORIZONTAL | 0x2)
00320 
00321 #define CS_REPOS_HCENTERSIZE    (CS_REPOS_HORIZONTAL | 0x3)
00322 
00323 #define CS_REPOS_TOP            (CS_REPOS_VERTICAL | 0x0)
00324 
00325 #define CS_REPOS_BOTTOM         (CS_REPOS_VERTICAL | 0x4)
00326 
00327 #define CS_REPOS_VCENTER        (CS_REPOS_VERTICAL | 0x8)
00328 
00329 #define CS_REPOS_VCENTERSIZE    (CS_REPOS_VERTICAL | 0xc)
00330 
00351 class CS_CSWS_EXPORT csComponent
00352 {
00353 protected:
00355   int state;
00357   csRect dirty;
00359   csRect clip;
00361   int *palette, palettesize;
00363   int *originalpalette;
00365   csRect OrgBound;
00367   char DragStyle;
00369   char ResizeMode;
00371   static int dragX;
00372   static int dragY;
00373   static int dragMode;
00375   static csRect *dragBound;
00377   csComponent *clipparent;
00379   char *text;
00381   iFont *Font;
00383   int FontSize;
00385   csArray<csComponent*> clipchildren;
00387   static cswsRectVector *visregion;
00388 
00389 public:
00390 #if (CS_PROCESSOR_SIZE == 32)
00391 # if (_MSC_VER >= 1300)
00392   /*
00393    * Silence VC7 64bit warning.
00394    */
00395   typedef unsigned int __w64 ID;
00396 # else
00397 
00398   typedef unsigned int ID;
00399 # endif
00400 #else
00401   /*
00402    * At some places, pointers are casted to csHashKey. Work around truncation
00403    * problems by forcing csHashKey to at least 64bit on 64bit machines.
00404    */
00405   typedef uint64 ID;
00406 #endif
00407 
00408 
00410   csComponent *focused;
00412   csComponent *top;
00414   csComponent *next, *prev;
00416   csComponent *parent;
00418   csApp *app;
00420   csSkinSlice *skinslice;
00422   void** skindata;
00424   ID id;
00426   csRect bound;
00427 
00429   csComponent (csComponent *iParent);
00431   virtual ~csComponent ();
00432 
00434   virtual void Insert (csComponent *comp);
00435 
00437   virtual void Delete (csComponent *comp);
00438 
00440   void DeleteAll ();
00441 
00443   void InsertClipChild (csComponent *clipchild);
00444 
00446   void DeleteClipChild (csComponent *clipchild);
00447 
00449   csComponent *GetClipParent ()
00450   { return clipparent; }
00451 
00453   virtual bool SetFocused (csComponent *comp);
00454 
00456   csComponent *GetFocused ()
00457   { return focused; }
00458 
00460   bool Select ();
00461 
00463   virtual csComponent *NextChild (csComponent *start = 0, bool disabled = false);
00464 
00466   virtual csComponent *PrevChild (csComponent *start = 0, bool disabled = false);
00467 
00469   virtual csComponent *NextControl (csComponent *start = 0);
00470 
00472   virtual csComponent *PrevControl (csComponent *start = 0);
00473 
00475   virtual csComponent *NextGroup (csComponent *start = 0);
00476 
00478   virtual csComponent *PrevGroup (csComponent *start = 0);
00479 
00481   bool FixFocused ();
00482 
00487   bool SetZorder (csComponent *comp, csComponent *below);
00488 
00490   csComponent *GetTop ()
00491   { return top; }
00492 
00503   void SetPalette (int *iPalette, int iPaletteSize);
00504 
00506   void SetPalette (int iPaletteID)
00507   { SetPalette (cswsPalette [iPaletteID].Palette, cswsPalette [iPaletteID].Size); }
00508 
00510   void ResetPalette ();
00511 
00513   void SetColor (int Index, int Color);
00514 
00516   int GetColor (int Index)
00517    { if (Index & 0x80000000) return Index;
00518     if (Index >= palettesize) return cs_Color_Red_L; else return palette[Index]; }
00519 
00526   virtual void SetText (const char *iText);
00528   virtual void GetText (char *oText, size_t iTextSize) const;
00530   virtual const char *GetText () const { return text; }
00531 
00538   csComponent *ForEach (bool (*func) (csComponent *child, void *param),
00539     void *param = 0, bool Zorder = false);
00540 
00542   csComponent *GetChild (ID find_id) const;
00543 
00545   void SetApp (csApp *newapp);
00546 
00548   virtual bool HandleEvent (iEvent &Event);
00549 
00556   virtual bool PreHandleEvent (iEvent &Event);
00557 
00559   virtual bool PostHandleEvent (iEvent &Event);
00560 
00562   void *SendCommand (int CommandCode, void *Info = 0);
00564   void *SendBroadcast (int CommandCode, void *Info = 0);
00565 
00567   csComponent *GetDefault ();
00568 
00570   void Redraw ();
00571 
00573   virtual void Draw ();
00574 
00576   virtual void Show (bool focused = false);
00577 
00579   virtual void Hide ();
00580 
00582   virtual bool SetRect (int xmin, int ymin, int xmax, int ymax);
00583 
00585   bool SetRect (csRect &rect)
00586   { return SetRect (rect.xmin, rect.ymin, rect.xmax, rect.ymax); }
00587 
00589   bool SetDragRect (int xmin, int ymin, int xmax, int ymax);
00590 
00592   void SetPos (int x, int y)
00593   { SetRect (x, y, x + bound.xmax - bound.xmin, y + bound.ymax - bound.ymin); }
00594 
00596   void SetSize (int w, int h)
00597   { SetRect (bound.xmin, bound.ymin, bound.xmin + w, bound.ymin + h); }
00598 
00600   void Center (bool iHoriz = true, bool iVert = true);
00601 
00603   virtual bool Maximize ();
00604 
00606   virtual bool Restore ();
00607 
00616   void Invalidate (csRect &area, bool IncludeChildren = false,
00617     csComponent *below = 0);
00618 
00620   void Invalidate (int xmin, int ymin, int xmax, int ymax,
00621     bool IncludeChildren = false, csComponent *below = 0)
00622   {
00623     csRect inv (xmin, ymin, xmax, ymax);
00624     Invalidate (inv, IncludeChildren, below);
00625   }
00626 
00628   void Invalidate (bool IncludeChildren = false, csComponent *below = 0)
00629   { Invalidate (-99999, -99999, +99999, +99999, IncludeChildren, below); }
00630 
00632   virtual void SetState (int mask, bool enable);
00633 
00635   int GetState (int mask)
00636   { return (state & mask); }
00637 
00639   void SetDragStyle (int iDragStyle)
00640   { DragStyle = iDragStyle; }
00641 
00643   int GetDragStyle ()
00644   { return DragStyle; }
00645 
00647   void SetResizeMode (int iResizeMode)
00648   { ResizeMode = iResizeMode; }
00649 
00651   int GetResizeMode ()
00652   { return ResizeMode; }
00653 
00655   void LocalToGlobal (int &x, int &y);
00656 
00658   void GlobalToLocal (int &x, int &y);
00659 
00665   void OtherToThis (csComponent *from, int &x, int &y);
00666 
00668   void Drag (int x, int y, int DragMode);
00669 
00671   void SetMouse (csMouseCursorID Cursor);
00672 
00678   virtual void Close ();
00679 
00690   csComponent *GetChildAt (int x, int y,
00691     bool (*func) (csComponent *, void *) = 0, void *data = 0);
00692 
00697   void SetSizingCursor (int dragtype);
00698 
00700   bool GetMousePosition (int &x, int &y);
00701 
00724   bool HandleDragEvent (iEvent &Event, int BorderW, int BorderH);
00725 
00727   virtual void FixPosition (int &newX, int &newY);
00728 
00730   virtual void FixSize (int &newW, int &newH);
00731 
00733   virtual void SuggestSize (int &w, int &h);
00734 
00736   virtual void SetSuggestedSize (int dw, int dh);
00737 
00739   void FindMaxFreeRect (csRect &area);
00740 
00742   virtual char *GetSkinName ();
00743 
00745   virtual csSkin *GetSkin ();
00746 
00764   void SetClipRect (int xmin, int ymin, int xmax, int ymax)
00765   { clip.Set (xmin, ymin, xmax, ymax); }
00766 
00768   void SetClipRect ()
00769   { clip.MakeEmpty (); }
00770 
00772   void SetFont (iFont *iNewFont);
00773 
00775   virtual void GetFont (iFont *&oFont);
00776 
00778   void Box (int xmin, int ymin, int xmax, int ymax, int colindx);
00779 
00781   void Line (float x1, float y1, float x2, float y2, int colindx);
00782 
00784   void Pixel (int x, int y, int colindx);
00785 
00787   void Text (int x, int y, int fgindx, int bgindx, const char *s);
00788 
00790   void Pixmap (csPixmap *s2d, int x, int y, int w, int h, uint8 Alpha = 0);
00792   void Pixmap (csPixmap *s2d, int x, int y, uint8 Alpha = 0)
00793   { Pixmap (s2d, x, y, s2d->Width (), s2d->Height (), Alpha); }
00795   void Pixmap (csPixmap *s2d, int x, int y, int w, int h, int orgx, int orgy,
00796     uint8 Alpha = 0);
00798   void Texture (iTextureHandle *tex, int x, int y, int w, int h,
00799     int orgx, int orgy, uint8 Alpha = 0);
00800 
00802   int GetTextSize (const char *text, int *oHeight = 0);
00804   int GetTextChars (const char *text, int iWidth);
00805 
00807   void Rect3D (int xmin, int ymin, int xmax, int ymax, int darkindx, int lightindx);
00808 
00810   void ObliqueRect3D (int xmin, int ymin, int xmax, int ymax, int cornersize,
00811     int darkindx, int lightindx);
00812 
00814   void Clear (int colindx)
00815   { Box (0, 0, bound.Width (), bound.Height (), colindx); }
00816 
00818   void ClearZbuffer (int xmin, int ymin, int xmax, int ymax);
00819 
00821   void ClearZbuffer ()
00822   { ClearZbuffer (0, 0, bound.Width (), bound.Height ()); }
00823 
00825   //@@@REIMPLEMENT THIS FOR NR
00826   //void Polygon3D (G3DPolygonDPFX &poly, uint mode);
00827 
00829 
00831   void DrawUnderline (int iX, int iY, const char *iText, size_t iUnderlinePos,
00832     int iColor);
00833 
00834 protected:
00840   void Clip (cswsRectVector &rect, csComponent *last, bool forchild = false);
00841 
00843   void ClipChild (cswsRectVector &rect, csComponent *child);
00844 
00851   void FastClip (cswsRectVector &rect);
00852 
00858   static void PrepareLabel (const char *iLabel, char * &oLabel, size_t &oUnderlinePos);
00859 
00861   bool CheckHotKey (iEvent &iEvent, char iHotKey);
00862 
00864   static size_t WordLeft (const char *iText, size_t StartPos);
00866   static size_t WordRight (const char *iText, size_t StartPos);
00867 
00869   bool ApplySkin (csSkin *Skin);
00870 
00879   void CheckDirtyTD (csRect &ioR);
00887   void CheckDirtyBU (csRect &ioR);
00888 
00889 private:
00890   static bool do_handle_event (csComponent *child, void *param);
00891 };
00892 
00895 #endif // __CS_CSCOMP_H__

Generated for Crystal Space by doxygen 1.3.9.1