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 : virtual public GEventsI
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     bool OnScriptEvent(GViewI *Ctrl) { return false; }
00129     int OnEvent(GMessage *Msg) { return 0; }
00130     void OnMouseEnter(GMouse &m) {}
00131     void OnMouseExit(GMouse &m) {}
00132     void OnMouseMove(GMouse &m) {}
00133     void OnMouseWheel(double Lines) {}
00134     bool OnKey(GKey &k) { return false; }
00135     void OnAttach() {}
00136     void OnCreate() {}
00137     void OnDestroy() {}
00138     void OnFocus(bool f) {}
00139     void OnPulse() {}
00140     void OnPosChange() {}
00141     bool OnRequestClose(bool OsShuttingDown) { return false; }
00142     int OnHitTest(int x, int y) { return 0; }
00143     void OnChildrenChanged(GViewI *Wnd, bool Attaching) {}
00144     void OnPaint(GSurface *pDC) {}
00145     int OnNotify(GViewI *Ctrl, int Flags) { return 0; }
00146     int OnCommand(int Cmd, int Event, OsView Wnd) { return 0; }
00147 };
00148 
00150 class GItemEdit : public GPopup
00151 {
00152     class GItemEditPrivate *d;
00153 
00154 public:
00155     GItemEdit(GView *parent, GItem *item, int index, int selstart, int selend);
00156     ~GItemEdit();
00157     
00158     void OnPaint(GSurface *pDC);
00159     int OnNotify(GViewI *v, int f);
00160     void Visible(bool i);
00161     int OnEvent(GMessage *Msg);
00162 };
00163 
00166 #define GLI_MARK_NONE               0
00169 #define GLI_MARK_UP_ARROW           1
00172 #define GLI_MARK_DOWN_ARROW         2
00173 
00175 class LgiClass GListColumn
00176     : public ResObject
00177 {
00178     class GListColumnPrivate *d;
00179     friend class GDragColumn;
00180     friend class GListItem;
00181     friend class GList;
00182 
00183 public:
00184     GListColumn(GList *parent, char *name, int width);
00185     virtual ~GListColumn();
00186 
00187     // properties
00188     
00190     void Name(char *n);
00192     char *Name();
00194     void Width(int i);
00196     int Width();
00200     void Type(int i);
00202     int Type();
00204     void Mark(int i);
00206     int Mark();
00208     void Icon(GSurface *i, bool Own = true);
00210     GSurface *Icon();
00212     int Value();
00213     
00215     void Image(int i);
00217     int Image();
00219     bool Resizable();
00221     void Resizable(bool i);
00222 
00224     int GetIndex();
00226     int GetContentSize();
00228     GList *GetList();
00229 
00231     void OnPaint(GSurface *pDC, GRect &r);
00232 
00234     void OnPaint_Content(GSurface *pDC, GRect &r, bool FillBackground); 
00235 };
00236 
00237 class LgiClass GListItemPainter
00238 {
00239 public:
00240     // Overridable
00241     virtual void OnPaintColumn(GSurface *pDC, GRect &r, int i, GListColumn *c) {}
00242 };
00243 
00244 class LgiClass GListItemColumn : public GObject, public GItem, public GListItemPainter
00245 {
00246     GListItem *_Item;
00247     int _Column;
00248     int _Value;
00249 
00250 protected:
00251     List<GListItem> *GetAllItems();
00252     GListItemColumn *GetItemCol(GListItem *i, int Col);
00253 
00254 public:
00255     GListItemColumn(GListItem *item, int col);
00256 
00257     // Other objects
00258     GListItem *GetItem() { return _Item; }
00259     GList *GetList();
00260 
00261     // Props
00262     int GetColumn() { return _Column; }
00263     void SetColumn(int i) { _Column = i; }
00264     virtual int Value() { return _Value; }
00265     virtual void Value(int i);
00266 };
00267 
00269 class LgiClass GListItem : public GItem, public GListItemPainter
00270 {
00271     friend class GList;
00272     friend class GListItemColumn;
00273     friend class GListColumn;
00274 
00275     void OnEditLabelEnd();
00276 
00277 protected:
00278     // Data
00279     class GListItemPrivate *d;
00280     GRect Pos;
00281     GList *Parent;
00282     COLOUR Fore;
00283     COLOUR Back;
00284 
00285     // Methods
00286     bool GridLines();
00287     GDisplayString *GetDs(int Col, int FitTo = -1);
00288 
00289 public:
00290     // Application defined, defaults to 0
00291     void *_UserData;
00292 
00293     // Object
00294     GListItem();
00295     virtual ~GListItem();
00296 
00298     GList *GetList() { return Parent; }
00300     List<GListItemColumn> *GetItemCols();
00301 
00302     // Properties
00303     
00305     bool SetText(char *s, int i=0);
00311     char *GetText(int i);
00314     int GetImage(int Flags = 0);
00316     void SetImage(int i);
00318     bool Select();
00320     void Select(bool b);
00322     GRect *GetPos(int Col = -1);
00324     bool OnScreen() { return Pos.y1 < Pos.y2; }
00325 
00326     // Methods
00327     
00329     void Update();
00331     void ScrollTo();
00333     void SetEditLabelSelection(int SelStart, int SelEnd); // call before 'EditLabel'
00335     GView *EditLabel(int Col = -1);
00336     
00337     // Events;
00338     void OnMouseClick(GMouse &m);
00339     void OnMeasure(GMeasureInfo *Info);
00340     void OnPaint(GSurface *pDC, GRect &r);
00341     void OnPaintColumn(GSurface *pDC, GRect &r, int i, GListColumn *c);
00342 
00343     // Overridable
00344     virtual int Compare(GListItem *To, int Field) { return 0; }
00345     virtual void OnColumnNotify(int Col, int Data) {}
00346 };
00347 
00348 typedef int (*GListCompareFunc)(GListItem *a, GListItem *b, int Data);
00349 
00351 class LgiClass GList :
00352     public GLayout,
00353     public GItemContainer,
00354     public ResObject
00355 {
00356     friend class GListItem;
00357     friend class GListColumn;
00358     friend class GListItemColumn;
00359     COLOUR _Selection;
00360 
00361     #ifdef WIN32
00362     HCURSOR Cursor;
00363     #endif
00364     
00365 protected:
00366     class GListPrivate *d;
00367 
00368     // Contents
00369     List<GListColumn> Columns;
00370     List<GListItem> Items;
00371     int Keyboard; // index of the item with keyboard focus
00372 
00373     // Flags
00374     bool ColumnHeaders;
00375     bool EditLabels;
00376     bool GridLines;
00377     bool MultiItemSelect;
00378 
00379     // Double buffered
00380     GSurface *Buf;
00381 
00382     // Drawing locations
00383     GRect ItemsPos;
00384     GRect ColumnHeader;
00385     GRect ScrollX, ScrollY;
00386     int FirstVisible;
00387     int LastVisible;
00388     int CompletelyVisible;
00389     GListColumn *IconCol;
00390 
00391     // Misc
00392     bool GetUpdateRegion(GListItem *i, GRegion &r);
00393     GListItem *HitItem(int x, int y, int *Index = 0);
00394     GRect &GetClientRect();
00395     void Pour();
00396     void UpdateScrollBars();
00397     void KeyScroll(int iTo, int iFrom, bool SelectItems);
00398     int HitColumn(int x, int y, GListColumn *&Resize, GListColumn *&Over);
00399 
00400 public:
00402     GList
00403     (
00405         int id,
00407         int x,
00409         int y,
00411         int cx,
00413         int cy,
00415         char *name = "List"
00416     );
00417     ~GList();
00418 
00419     // Overridables
00420     
00422     virtual void OnItemClick
00423     (
00425         GListItem *Item,
00427         GMouse &m
00428     );
00430     virtual void OnItemBeginDrag
00431     (
00433         GListItem *Item,
00435         GMouse &m
00436     );
00440     virtual void OnItemSelect
00441     (
00443         GListItem *Item
00444     );
00446     virtual void OnColumnClick
00447     (
00449         int Col,
00451         GMouse &m
00452     );
00454     virtual void OnColumnDrag
00455     (
00457         int Col,
00459         GMouse &m
00460     ) {}
00462     virtual bool OnColumnReindex
00463     (
00465         GListColumn *Col,
00467         int OldIndex,
00469         int NewIndex
00470     )
00471     {
00472         return false;
00473     }
00474     
00475     // Events
00476     
00477     void OnPaint(GSurface *pDC);
00478     int OnEvent(GMessage *Msg);
00479     int OnHitTest(int x, int y);
00480     void OnMouseClick(GMouse &m);
00481     void OnMouseMove(GMouse &m);
00482     int OnNotify(GViewI *Ctrl, int Flags);
00483     void OnPosChange();
00484     bool OnKey(GKey &k);
00485     void OnMouseWheel(double Lines);
00486     void OnFocus(bool b);
00487     void OnPulse();
00488 
00489     // Columns
00490     
00492     GListColumn *AddColumn
00493     (
00495         char *Name,
00497         int Width = 50,
00499         int Where = -1
00500     );
00502     bool AddColumn
00503     (
00505         GListColumn *Col,
00507         int Where = -1
00508     );
00510     bool DeleteColumn(GListColumn *Col);
00512     void EmptyColumns();
00514     GListColumn *ColumnAt(int Index) { return Columns.ItemAt(Index); }
00516     int ColumnAtX(int X, GListColumn **Col = 0, int *Offset = 0);
00518     int GetColumns() { return Columns.Length(); }
00520     void DragColumn(int Index);
00522     bool GetColumnClickInfo(int &Col, GMouse &m);
00523 
00524     // Properties
00525     
00527     bool ShowColumnHeader() { return ColumnHeaders; }
00529     void ShowColumnHeader(bool Show) { ColumnHeaders = Show; }
00531     bool AllowEditLabels() { return EditLabels; }
00533     void AllowEditLabels(bool b) { EditLabels = b; }
00535     bool DrawGridLines() { return GridLines; }
00537     void DrawGridLines(bool b) { GridLines = b; }
00539     bool MultiSelect() { return MultiItemSelect; }
00541     void MultiSelect(bool b) { MultiItemSelect = b; }
00542 
00543     // Methods
00544     
00547     GListMode GetMode();
00550     void SetMode(GListMode m);  
00551 
00553     int Value();
00555     void Value(int i);
00557     bool Select(GListItem *Obj);
00559     GListItem *GetSelection();
00561     bool GetSelection(List<GListItem> &l);
00563     void SelectAll();
00565     bool GetAll(List<GListItem> &l);
00567     void ScrollToSelection();
00569     void UpdateAllItems();
00570 
00571     // List
00572     
00574     GListItem *First() { return Items.First(); }
00576     GListItem *Last() { return Items.Last(); }
00578     GListItem *Next() { return Items.Next(); }
00580     GListItem *Prev() { return Items.Prev(); }
00582     GListItem *Current() { return Items.Current(); }
00584     int Length() { return Items.Length(); }
00585 
00587     bool IsEmpty() { return Items.Length() == 0; }
00589     bool Delete();
00591     bool Delete(int Index);
00593     bool Delete(GListItem *p);
00595     bool Insert
00596     (
00598         GListItem *p,
00600         int Index = -1,
00603         bool Update = true
00604     );
00606     bool Insert
00607     (
00609         List<GListItem> &l,
00611         int Index = -1,
00614         bool Update = true
00615     );
00617     bool Remove(GListItem *Obj);
00619     bool HasItem(GListItem *Obj);
00621     int IndexOf(GListItem *Obj);
00623     GListItem *ItemAt(int Index);
00625     void Sort
00626     (
00628         GListCompareFunc Compare,
00630         int Data
00631     );
00632 
00634     void Empty();           
00636     void RemoveAll();
00638     void ResizeColumnsToContent(int Border = DEFAULT_COLUMN_SPACING);
00639 };
00640 
00641 #endif

Generated on Tue May 2 10:24:42 2006 for Lgi by  doxygen 1.4.1