00001
00002
00003
00004
00005 #ifndef __GLIST2_H
00006 #define __GLIST2_H
00007
00008
00009 #include "GPopup.h"
00010 #include "GArray.h"
00011
00012
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_BACKSPACE 9
00046 #define GLIST_NOTIFY_RETURN 13
00049 #define GLIST_NOTIFY_DEL_KEY 14
00052 #define GLIST_NOTIFY_ESC_KEY 15
00054 #define GLIST_NOTIFY_ITEMS_DROPPED 16
00058 #define GLIST_NOTIFY_CONTEXT_MENU 17
00059
00060
00061 #define WM_END_EDIT_LABEL (WM_USER+0x556)
00062
00063
00064 #define DEFAULT_COLUMN_SPACING 12
00065
00067
00069 enum GListMode
00070 {
00071 GListDetails,
00072 GListColumns,
00073 GListSpacial,
00074 };
00075
00077 class LgiClass GMeasureInfo
00078 {
00079 public:
00081 int x;
00083 int y;
00084 };
00085
00087 class LgiClass GItem : virtual public GEventsI
00088 {
00089 GAutoPtr<GViewFill> _Fore, _Back;
00090
00091 public:
00093 struct ItemPaintCtx : public GRect
00094 {
00096 GSurface *pDC;
00097
00099 COLOUR Fore;
00101 COLOUR Back;
00102 };
00103
00104 GItem &operator =(GItem &i)
00105 {
00106 if (i._Fore.Get())
00107 _Fore.Reset(new GViewFill(*i._Fore));
00108 else
00109 _Fore.Reset();
00110
00111 if (i._Back.Get())
00112 _Back.Reset(new GViewFill(*i._Back));
00113 else
00114 _Back.Reset();
00115
00116 return *this;
00117 }
00118
00119
00120
00122 virtual void OnSelect() {}
00124 virtual void OnMouseClick(GMouse &m) {}
00126 virtual void OnPaint(ItemPaintCtx &Ctx) = 0;
00128 virtual bool OnBeginDrag(GMouse &m) { return false; }
00130 virtual void OnMeasure(GMeasureInfo *Info) {}
00132 virtual void OnInsert() {}
00134 virtual void OnRemove() {}
00135
00136
00137
00139 virtual void Update() {}
00141 virtual void ScrollTo() {}
00143 virtual GView *EditLabel(int Col = -1) { return 0; }
00145 virtual void OnEditLabelEnd() {}
00146
00147
00148
00150 virtual bool Select() { return false; }
00152 virtual void Select(bool b) {}
00154 virtual char *GetText(int Col=0) { return 0; }
00156 virtual bool SetText(const char *s, int Col=0) { return false; }
00158 virtual int GetImage(int Flags = 0) { return -1; }
00160 virtual void SetImage(int Col) {}
00162 virtual GRect *GetPos(int Col = -1) { return 0; }
00164 virtual GFont *GetFont() { return 0; }
00166 virtual GViewFill *GetForegroundFill() { return _Fore; }
00168 virtual void SetForegroundFill(GViewFill *Fill) { _Fore.Reset(Fill); }
00170 virtual GViewFill *GetBackgroundFill() { return _Back; }
00172 virtual void SetBackgroundFill(GViewFill *Fill) { _Back.Reset(Fill); }
00173
00175 virtual bool XmlIo(class GXmlTag *Tag, bool Write) { return false; }
00176
00177 bool OnScriptEvent(GViewI *Ctrl) { return false; }
00178 int OnEvent(GMessage *Msg) { return 0; }
00179 void OnMouseEnter(GMouse &m) {}
00180 void OnMouseExit(GMouse &m) {}
00181 void OnMouseMove(GMouse &m) {}
00182 void OnMouseWheel(double Lines) {}
00183 bool OnKey(GKey &k) { return false; }
00184 void OnAttach() {}
00185 void OnCreate() {}
00186 void OnDestroy() {}
00187 void OnFocus(bool f) {}
00188 void OnPulse() {}
00189 void OnPosChange() {}
00190 bool OnRequestClose(bool OsShuttingDown) { return false; }
00191 int OnHitTest(int x, int y) { return 0; }
00192 void OnChildrenChanged(GViewI *Wnd, bool Attaching) {}
00193 int OnNotify(GViewI *Ctrl, int Flags) { return 0; }
00194 int OnCommand(int Cmd, int Event, OsView Wnd) { return 0; }
00195 void OnPaint(GSurface *pDC) { LgiAssert(0); }
00196 };
00197
00199 class GItemEdit : public GPopup
00200 {
00201 class GItemEditPrivate *d;
00202
00203 public:
00204 GItemEdit(GView *parent, GItem *item, int index, int selstart, int selend);
00205 ~GItemEdit();
00206
00207 void OnPaint(GSurface *pDC);
00208 int OnNotify(GViewI *v, int f);
00209 void Visible(bool i);
00210 int OnEvent(GMessage *Msg);
00211 };
00212
00215 #define GLI_MARK_NONE 0
00218 #define GLI_MARK_UP_ARROW 1
00221 #define GLI_MARK_DOWN_ARROW 2
00222
00224 class LgiClass GListColumn
00225 : public ResObject
00226 {
00227 class GListColumnPrivate *d;
00228 friend class GDragColumn;
00229 friend class GListItem;
00230 friend class GList;
00231
00232 public:
00233 GListColumn(GList *parent, const char *name, int width);
00234 virtual ~GListColumn();
00235
00236
00237
00239 void Name(const char *n);
00241 char *Name();
00243 void Width(int i);
00245 int Width();
00249 void Type(int i);
00251 int Type();
00253 void Mark(int i);
00255 int Mark();
00257 void Icon(GSurface *i, bool Own = true);
00259 GSurface *Icon();
00261 int Value();
00262
00264 void Image(int i);
00266 int Image();
00268 bool Resizable();
00270 void Resizable(bool i);
00271
00273 int GetIndex();
00275 int GetContentSize();
00277 GList *GetList();
00278
00280 void OnPaint(GSurface *pDC, GRect &r);
00281
00283 void OnPaint_Content(GSurface *pDC, GRect &r, bool FillBackground);
00284 };
00285
00286 class LgiClass GListItemPainter
00287 {
00288 public:
00289
00290 virtual void OnPaintColumn(GItem::ItemPaintCtx &Ctx, int i, GListColumn *c) = 0;
00291 };
00292
00293 class LgiClass GListItemColumn : public GBase, public GItem, public GListItemPainter
00294 {
00295 GListItem *_Item;
00296 int _Column;
00297 int _Value;
00298
00299 void OnPaint(ItemPaintCtx &Ctx) {}
00300
00301 protected:
00302 List<GListItem> *GetAllItems();
00303 GListItemColumn *GetItemCol(GListItem *i, int Col);
00304
00305 public:
00306 GListItemColumn(GListItem *item, int col);
00307
00308
00309 GListItem *GetItem() { return _Item; }
00310 GList *GetList();
00311
00312
00313 int GetColumn() { return _Column; }
00314 void SetColumn(int i) { _Column = i; }
00315 virtual int64 Value() { return _Value; }
00316 virtual void Value(int64 i);
00317 };
00318
00320 class LgiClass GListItem : public GItem, public GListItemPainter
00321 {
00322 friend class GList;
00323 friend class GListItemColumn;
00324 friend class GListColumn;
00325
00326 void OnEditLabelEnd();
00327
00328 protected:
00329
00330 class GListItemPrivate *d;
00331 GRect Pos;
00332 GList *Parent;
00333
00334
00335 bool GridLines();
00336 GDisplayString *GetDs(int Col, int FitTo = -1);
00337
00338 public:
00339
00340 void *_UserData;
00341
00342
00343 GListItem();
00344 virtual ~GListItem();
00345
00347 GList *GetList() { return Parent; }
00349 List<GListItemColumn> *GetItemCols();
00350
00351
00352
00354 bool SetText(const char *s, int i=0);
00355
00363 char *GetText
00364 (
00366 int i
00367 );
00368
00371 int GetImage(int Flags = 0);
00373 void SetImage(int i);
00375 bool Select();
00377 void Select(bool b);
00379 GRect *GetPos(int Col = -1);
00381 bool OnScreen() { return Pos.y1 < Pos.y2; }
00382
00383
00384
00386 void Update();
00388 void ScrollTo();
00390 void SetEditLabelSelection(int SelStart, int SelEnd);
00392 GView *EditLabel(int Col = -1);
00393
00394
00395 void OnMouseClick(GMouse &m);
00396 void OnMeasure(GMeasureInfo *Info);
00397 void OnPaint(GSurface *pDC) { LgiAssert(0); }
00398 void OnPaint(GItem::ItemPaintCtx &Ctx);
00399 void OnPaintColumn(GItem::ItemPaintCtx &Ctx, int i, GListColumn *c);
00400
00401
00402 virtual int Compare(GListItem *To, int Field) { return 0; }
00403 virtual void OnColumnNotify(int Col, int Data) {}
00404 };
00405
00406 typedef int (*GListCompareFunc)(GListItem *a, GListItem *b, int Data);
00407
00408 class GListItems
00409 {
00410 protected:
00411 List<GListItem> Items;
00412
00413 public:
00414 template<class T>
00415 bool GetSelection(List<T> &n)
00416 {
00417 n.Empty();
00418 List<GListItem>::I It = Items.Start();
00419 for (GListItem *i=*It; i; i=*++It)
00420 {
00421 if (i->Select())
00422 {
00423 T *ptr = dynamic_cast<T*>(i);
00424 if (ptr)
00425 n.Insert(ptr);
00426 }
00427 }
00428 return n.Length() > 0;
00429 }
00430
00431 template<class T>
00432 bool GetAll(List<T> &n)
00433 {
00434 n.Empty();
00435 List<GListItem>::I It = Items.Start();
00436 for (GListItem *i=*It; i; i=*++It)
00437 {
00438 T *ptr = dynamic_cast<T*>(i);
00439 if (ptr)
00440 n.Insert(ptr);
00441 }
00442 return n.Length() > 0;
00443 }
00444
00445 List<GListItem>::I Start()
00446 {
00447 return Items.Start();
00448 }
00449
00450 List<GListItem>::I End()
00451 {
00452 return Items.End();
00453 }
00454 };
00455
00457 class LgiClass GList :
00458 public GLayout,
00459 public GItemContainer,
00460 public ResObject,
00461 public GListItems
00462 {
00463 friend class GListItem;
00464 friend class GListColumn;
00465 friend class GListItemColumn;
00466
00467 #ifdef WIN32
00468 HCURSOR Cursor;
00469 #endif
00470
00471 protected:
00472 class GListPrivate *d;
00473
00474
00475 List<GListColumn> Columns;
00476 int Keyboard;
00477
00478
00479 bool ColumnHeaders;
00480 bool EditLabels;
00481 bool GridLines;
00482 bool MultiItemSelect;
00483
00484
00485 GSurface *Buf;
00486
00487
00488 GRect ItemsPos;
00489 GRect ColumnHeader;
00490 GRect ScrollX, ScrollY;
00491 int FirstVisible;
00492 int LastVisible;
00493 int CompletelyVisible;
00494 GListColumn *IconCol;
00495
00496
00497 bool GetUpdateRegion(GListItem *i, GRegion &r);
00498 GListItem *HitItem(int x, int y, int *Index = 0);
00499 GRect &GetClientRect();
00500 void Pour();
00501 void UpdateScrollBars();
00502 void KeyScroll(int iTo, int iFrom, bool SelectItems);
00503 int HitColumn(int x, int y, GListColumn *&Resize, GListColumn *&Over);
00504
00505 public:
00507 GList
00508 (
00510 int id,
00512 int x,
00514 int y,
00516 int cx,
00518 int cy,
00520 const char *name = "List"
00521 );
00522 ~GList();
00523
00524 const char *GetClass() { return "GList"; }
00525
00526
00527
00529 virtual void OnItemClick
00530 (
00532 GListItem *Item,
00534 GMouse &m
00535 );
00537 virtual void OnItemBeginDrag
00538 (
00540 GListItem *Item,
00542 GMouse &m
00543 );
00547 virtual void OnItemSelect
00548 (
00550 GArray<GListItem*> &Items
00551 );
00553 virtual void OnColumnClick
00554 (
00556 int Col,
00558 GMouse &m
00559 );
00561 virtual void OnColumnDrag
00562 (
00564 int Col,
00566 GMouse &m
00567 ) {}
00570 virtual bool OnColumnReindex
00571 (
00573 GListColumn *Col,
00575 int OldIndex,
00577 int NewIndex
00578 )
00579 {
00580 return false;
00581 }
00582
00583
00584
00585 void OnPaint(GSurface *pDC);
00586 int OnEvent(GMessage *Msg);
00587 int OnHitTest(int x, int y);
00588 void OnMouseClick(GMouse &m);
00589 void OnMouseMove(GMouse &m);
00590 int OnNotify(GViewI *Ctrl, int Flags);
00591 void OnPosChange();
00592 bool OnKey(GKey &k);
00593 void OnMouseWheel(double Lines);
00594 void OnFocus(bool b);
00595 void OnPulse();
00596
00597
00598
00600 GListColumn *AddColumn
00601 (
00603 const char *Name,
00605 int Width = 50,
00607 int Where = -1
00608 );
00610 bool AddColumn
00611 (
00613 GListColumn *Col,
00615 int Where = -1
00616 );
00618 bool DeleteColumn(GListColumn *Col);
00620 void EmptyColumns();
00622 GListColumn *ColumnAt(int Index) { return Columns.ItemAt(Index); }
00624 int ColumnAtX(int X, GListColumn **Col = 0, int *Offset = 0);
00626 int GetColumns() { return Columns.Length(); }
00629 void DragColumn(int Index);
00631 bool GetColumnClickInfo(int &Col, GMouse &m);
00632
00633
00634
00636 bool ShowColumnHeader() { return ColumnHeaders; }
00638 void ShowColumnHeader(bool Show) { ColumnHeaders = Show; }
00640 bool AllowEditLabels() { return EditLabels; }
00642 void AllowEditLabels(bool b) { EditLabels = b; }
00644 bool DrawGridLines() { return GridLines; }
00646 void DrawGridLines(bool b) { GridLines = b; }
00648 bool MultiSelect() { return MultiItemSelect; }
00650 void MultiSelect(bool b) { MultiItemSelect = b; }
00651
00652
00653
00656 GListMode GetMode();
00659 void SetMode(GListMode m);
00660
00662 int64 Value();
00664 void Value(int64 i);
00666 bool Select(GListItem *Obj);
00668 GListItem *GetSelected();
00670 void SelectAll();
00672 void ScrollToSelection();
00674 void UpdateAllItems();
00676 int Length() { return Items.Length(); }
00677
00679 bool IsEmpty() { return Items.Length() == 0; }
00681 bool Delete();
00683 bool Delete(int Index);
00685 virtual bool Delete(GListItem *p);
00687 virtual bool Remove(GListItem *Obj);
00689 bool Insert
00690 (
00692 GListItem *p,
00694 int Index = -1,
00697 bool Update = true
00698 );
00700 virtual bool Insert
00701 (
00703 List<GListItem> &l,
00705 int Index = -1,
00708 bool Update = true
00709 );
00711 bool HasItem(GListItem *Obj);
00713 int IndexOf(GListItem *Obj);
00715 GListItem *ItemAt(int Index);
00717 void Sort
00718 (
00720 GListCompareFunc Compare,
00722 int Data
00723 );
00724
00726 virtual void Empty();
00728 virtual void RemoveAll();
00730 void ResizeColumnsToContent(int Border = DEFAULT_COLUMN_SPACING);
00731 };
00732
00733 #endif