Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

GList.h

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 #ifndef __GLIST2_H
00006 #define __GLIST2_H
00007 
00008 // Includes
00009 #include "GPopup.h"
00010 #include "GArray.h"
00011 
00012 // GList notification flags
00013 
00016 #define GLIST_NOTIFY_INSERT         0
00019 #define GLIST_NOTIFY_DELETE         1
00022 #define GLIST_NOTIFY_SELECT         2
00025 #define GLIST_NOTIFY_CLICK          3
00028 #define GLIST_NOTIFY_DBL_CLICK      4
00031 #define GLIST_NOTIFY_CHANGE         5
00034 #define GLIST_NOTIFY_COLS_CHANGE    6
00037 #define GLIST_NOTIFY_COLS_SIZE      7
00040 #define GLIST_NOTIFY_COLS_CLICK     8
00043 #define GLIST_NOTIFY_RETURN         13
00046 #define GLIST_NOTIFY_DEL_KEY        14
00049 #define GLIST_NOTIFY_ESC_KEY        15
00050 
00051 // Messages
00052 #define WM_END_EDIT_LABEL           (WM_USER+0x556)
00053 
00054 // Constants
00055 #define DEFAULT_COLUMN_SPACING      12
00056 
00058 
00060 enum GListMode
00061 {
00062     GListDetails,
00063     GListColumns,
00064     GListSpacial,
00065 };
00066 
00068 class LgiClass GMeasureInfo
00069 {
00070 public:
00072     int x;
00074     int y;
00075 };
00076 
00078 class LgiClass GItem : public GEvent
00079 {
00080 public:
00081     // Events
00082     
00084     virtual void OnSelect() {}
00086     virtual void OnMouseClick(GMouse &m) {}
00088     virtual void OnPaint(GSurface *pDC, GRect &r) {}
00090     virtual bool OnBeginDrag(GMouse &m) { return false; }
00092     virtual void OnMeasure(GMeasureInfo *Info) {}
00094     virtual void OnInsert() {}
00096     virtual void OnRemove() {}
00097 
00098     // Methods
00099 
00101     virtual void Update() {}
00103     virtual void ScrollTo() {}
00105     virtual GView *EditLabel(int Col = -1) { return 0; }
00107     virtual void OnEditLabelEnd() {}
00108 
00109     // Data
00110 
00112     virtual bool Select() { return false; }
00114     virtual void Select(bool b) {}
00116     virtual char *GetText(int Col=0) { return 0; }
00118     virtual bool SetText(char *s, int Col=0) { return false; }
00120     virtual int GetImage(int Flags = 0) { return -1; }
00122     virtual void SetImage(int Col) {}
00124     virtual GRect *GetPos(int Col = -1) { return 0; }
00126     virtual GFont *GetFont() { return 0; }
00127 };
00128 
00130 class GItemEdit : public GPopup
00131 {
00132     class GItemEditPrivate *d;
00133 
00134 public:
00135     GItemEdit(GView *parent, GItem *item, int index, int selstart, int selend);
00136     ~GItemEdit();
00137     
00138     void OnPaint(GSurface *pDC);
00139     int OnNotify(GView *v, int f);
00140     void Visible(bool i);
00141     int OnEvent(GMessage *Msg);
00142 };
00143 
00146 #define GLI_MARK_NONE               0
00149 #define GLI_MARK_UP_ARROW           1
00152 #define GLI_MARK_DOWN_ARROW         2
00153 
00155 class LgiClass GListColumn
00156     : public ResObject
00157 {
00158     class GListColumnPrivate *d;
00159     friend class GDragColumn;
00160     friend class GListItem;
00161     friend class GList;
00162 
00163 public:
00164     GListColumn(GList *parent, char *name, int width);
00165     virtual ~GListColumn();
00166 
00167     // properties
00168     
00170     void Name(char *n);
00172     char *Name();
00174     void Width(int i);
00176     int Width();
00180     void Type(int i);
00182     int Type();
00184     void Mark(int i);
00186     int Mark();
00188     void Icon(GSurface *i, bool Own = true);
00190     GSurface *Icon();
00192     int Value();
00193     
00195     void Image(int i);
00197     int Image();
00199     bool Resizable();
00201     void Resizable(bool i);
00202 
00204     int GetIndex();
00206     int GetContentSize();
00208     GList *GetList();
00209 
00211     void OnPaint(GSurface *pDC, GRect &r);
00212 
00214     void OnPaint_Content(GSurface *pDC, GRect &r, bool FillBackground); 
00215 };
00216 
00217 class LgiClass GListItemPainter
00218 {
00219 public:
00220     // Overridable
00221     virtual void OnPaintColumn(GSurface *pDC, GRect &r, int i, GListColumn *c) {}
00222 };
00223 
00224 class LgiClass GListItemColumn : public GObject, public GItem, public GListItemPainter
00225 {
00226     GListItem *_Item;
00227     int _Column;
00228     int _Value;
00229 
00230 protected:
00231     List<GListItem> *GetAllItems();
00232     GListItemColumn *GetItemCol(GListItem *i, int Col);
00233 
00234 public:
00235     GListItemColumn(GListItem *item, int col);
00236 
00237     // Other objects
00238     GListItem *GetItem() { return _Item; }
00239     GList *GetList();
00240 
00241     // Props
00242     int GetColumn() { return _Column; }
00243     void SetColumn(int i) { _Column = i; }
00244     virtual int Value() { return _Value; }
00245     virtual void Value(int i);
00246 };
00247 
00249 class LgiClass GListItem : public GItem, public GListItemPainter
00250 {
00251     friend class GList;
00252     friend class GListItemColumn;
00253     friend class GListColumn;
00254 
00255     void OnEditLabelEnd();
00256 
00257 protected:
00258     // Data
00259     class GListItemPrivate *d;
00260     GRect Pos;
00261     GList *Parent;
00262     COLOUR Fore;
00263     COLOUR Back;
00264 
00265     // Methods
00266     bool GridLines();
00267     GDisplayString *GetDs(int Col, int FitTo = -1);
00268 
00269 public:
00270     // Application defined, defaults to 0
00271     void *_UserData;
00272 
00273     // Object
00274     GListItem();
00275     virtual ~GListItem();
00276 
00278     GList *GetList() { return Parent; }
00280     List<GListItemColumn> *GetItemCols();
00281 
00282     // Properties
00283     
00285     bool SetText(char *s, int i=0);
00291     char *GetText(int i);
00294     int GetImage(int Flags = 0);
00296     void SetImage(int i);
00298     bool Select();
00300     void Select(bool b);
00302     GRect *GetPos(int Col = -1);
00304     bool OnScreen() { return Pos.y1 < Pos.y2; }
00305 
00306     // Methods
00307     
00309     void Update();
00311     void ScrollTo();
00313     void SetEditLabelSelection(int SelStart, int SelEnd); // call before 'EditLabel'
00315     GView *EditLabel(int Col = -1);
00316     
00317     // Events;
00318     void OnMouseClick(GMouse &m);
00319     void OnMeasure(GMeasureInfo *Info);
00320     void OnPaint(GSurface *pDC, GRect &r);
00321     void OnPaintColumn(GSurface *pDC, GRect &r, int i, GListColumn *c);
00322 
00323     // Overridable
00324     virtual int Compare(GListItem *To, int Field) { return 0; }
00325     virtual void OnColumnNotify(int Col, int Data) {}
00326 };
00327 
00328 typedef int (*GListCompareFunc)(GListItem *a, GListItem *b, int Data);
00329 
00331 class LgiClass GList :
00332     public GLayout,
00333     public GItemContainer,
00334     public ResObject
00335 {
00336     friend class GListItem;
00337     friend class GListColumn;
00338     friend class GListItemColumn;
00339     COLOUR _Selection;
00340 
00341     #ifdef WIN32
00342     HCURSOR Cursor;
00343     #endif
00344     
00345 protected:
00346     class GListPrivate *d;
00347 
00348     // Contents
00349     List<GListColumn> Columns;
00350     List<GListItem> Items;
00351     int Keyboard; // index of the item with keyboard focus
00352 
00353     // Flags
00354     bool ColumnHeaders;
00355     bool EditLabels;
00356     bool GridLines;
00357     bool MultiItemSelect;
00358 
00359     // Double buffered
00360     GSurface *Buf;
00361 
00362     // Drawing locations
00363     GRect ItemsPos;
00364     GRect ColumnHeader;
00365     GRect ScrollX, ScrollY;
00366     int FirstVisible;
00367     int LastVisible;
00368     int CompletelyVisible;
00369     GListColumn *IconCol;
00370 
00371     // Misc
00372     bool GetUpdateRegion(GListItem *i, GRegion &r);
00373     GListItem *HitItem(int x, int y, int *Index = 0);
00374     GRect &GetClientRect();
00375     void Pour();
00376     void UpdateScrollBars();
00377     void KeyScroll(int iTo, int iFrom, bool SelectItems);
00378     int HitColumn(int x, int y, GListColumn *&Resize, GListColumn *&Over);
00379 
00380 public:
00382     GList
00383     (
00385         int id,
00387         int x,
00389         int y,
00391         int cx,
00393         int cy,
00395         char *name = "List"
00396     );
00397     ~GList();
00398 
00399     // Overridables
00400     
00402     virtual void OnItemClick
00403     (
00405         GListItem *Item,
00407         GMouse &m
00408     );
00410     virtual void OnItemBeginDrag
00411     (
00413         GListItem *Item,
00415         GMouse &m
00416     );
00420     virtual void OnItemSelect
00421     (
00423         GListItem *Item
00424     );
00426     virtual void OnColumnClick
00427     (
00429         int Col,
00431         GMouse &m
00432     );
00434     virtual void OnColumnDrag
00435     (
00437         int Col,
00439         GMouse &m
00440     ) {}
00442     virtual bool OnColumnReindex
00443     (
00445         GListColumn *Col,
00447         int OldIndex,
00449         int NewIndex
00450     )
00451     {
00452         return false;
00453     }
00454     
00455     // Events
00456     
00457     void OnPaint(GSurface *pDC);
00458     int OnEvent(GMessage *Msg);
00459     int OnHitTest(int x, int y);
00460     void OnMouseClick(GMouse &m);
00461     void OnMouseMove(GMouse &m);
00462     int OnNotify(GView *Ctrl, int Flags);
00463     void OnPosChange();
00464     bool OnKey(GKey &k);
00465     void OnMouseWheel(double Lines);
00466     void OnFocus(bool b);
00467     void OnPulse();
00468 
00469     // Columns
00470     
00472     GListColumn *AddColumn
00473     (
00475         char *Name,
00477         int Width = 50,
00479         int Where = -1
00480     );
00482     bool AddColumn
00483     (
00485         GListColumn *Col,
00487         int Where = -1
00488     );
00490     bool DeleteColumn(GListColumn *Col);
00492     void EmptyColumns();
00494     GListColumn *ColumnAt(int Index) { return Columns.ItemAt(Index); }
00496     int ColumnAtX(int X, GListColumn **Col = 0, int *Offset = 0);
00498     int GetColumns() { return Columns.GetItems(); }
00500     void DragColumn(int Index);
00502     bool GetColumnClickInfo(int &Col, GMouse &m);
00503 
00504     // Properties
00505     
00507     bool ShowColumnHeader() { return ColumnHeaders; }
00509     void ShowColumnHeader(bool Show) { ColumnHeaders = Show; }
00511     bool AllowEditLabels() { return EditLabels; }
00513     void AllowEditLabels(bool b) { EditLabels = b; }
00515     bool DrawGridLines() { return GridLines; }
00517     void DrawGridLines(bool b) { GridLines = b; }
00519     bool MultiSelect() { return MultiItemSelect; }
00521     void MultiSelect(bool b) { MultiItemSelect = b; }
00522 
00523     // Methods
00524     
00527     GListMode GetMode();
00530     void SetMode(GListMode m);  
00531 
00533     int Value();
00535     void Value(int i);
00537     bool Select(GListItem *Obj);
00539     GListItem *GetSelection();
00541     bool GetSelection(List<GListItem> &l);
00543     void SelectAll();
00545     bool GetAll(List<GListItem> &l);
00547     void ScrollToSelection();
00549     void UpdateAllItems();
00550 
00551     // List
00552     
00554     GListItem *First() { return Items.First(); }
00556     GListItem *Last() { return Items.Last(); }
00558     GListItem *Next() { return Items.Next(); }
00560     GListItem *Prev() { return Items.Prev(); }
00562     GListItem *Current() { return Items.Current(); }
00564     int GetItems() { return Items.GetItems(); }
00565 
00567     bool IsEmpty() { return Items.GetItems() == 0; }
00569     bool Delete();
00571     bool Delete(int Index);
00573     bool Delete(GListItem *p);
00575     bool Insert
00576     (
00578         GListItem *p,
00580         int Index = -1,
00583         bool Update = true
00584     );
00586     bool Insert
00587     (
00589         List<GListItem> &l,
00591         int Index = -1,
00594         bool Update = true
00595     );
00597     bool Remove(GListItem *Obj);
00599     bool HasItem(GListItem *Obj);
00601     int IndexOf(GListItem *Obj);
00603     GListItem *ItemAt(int Index);
00605     void Sort
00606     (
00608         GListCompareFunc Compare,
00610         int Data
00611     );
00612 
00614     void Empty();           
00616     void RemoveAll();
00618     void ResizeColumnsToContent(int Border = DEFAULT_COLUMN_SPACING);
00619 };
00620 
00621 #endif

Generated on Wed Oct 26 14:46:49 2005 for Lgi by  doxygen 1.4.1