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
00053
00054
00055 #define WM_END_EDIT_LABEL (WM_USER+0x556)
00056
00057
00058 #define DEFAULT_COLUMN_SPACING 12
00059
00061
00063 enum GListMode
00064 {
00065 GListDetails,
00066 GListColumns,
00067 GListSpacial,
00068 };
00069
00071 class LgiClass GMeasureInfo
00072 {
00073 public:
00075 int x;
00077 int y;
00078 };
00079
00081 class LgiClass GItem : virtual public GEventsI
00082 {
00083 GAutoPtr<GViewFill> _Fore, _Back;
00084
00085 public:
00087 struct ItemPaintCtx : public GRect
00088 {
00090 GSurface *pDC;
00091
00093 COLOUR Fore;
00095 COLOUR Back;
00096 };
00097
00098 GItem &operator =(GItem &i)
00099 {
00100 if (i._Fore.Get())
00101 _Fore.Reset(new GViewFill(*i._Fore));
00102 else
00103 _Fore.Reset();
00104
00105 if (i._Back.Get())
00106 _Back.Reset(new GViewFill(*i._Back));
00107 else
00108 _Back.Reset();
00109
00110 return *this;
00111 }
00112
00113
00114
00116 virtual void OnSelect() {}
00118 virtual void OnMouseClick(GMouse &m) {}
00120 virtual void OnPaint(ItemPaintCtx &Ctx) = 0;
00122 virtual bool OnBeginDrag(GMouse &m) { return false; }
00124 virtual void OnMeasure(GMeasureInfo *Info) {}
00126 virtual void OnInsert() {}
00128 virtual void OnRemove() {}
00129
00130
00131
00133 virtual void Update() {}
00135 virtual void ScrollTo() {}
00137 virtual GView *EditLabel(int Col = -1) { return 0; }
00139 virtual void OnEditLabelEnd() {}
00140
00141
00142
00144 virtual bool Select() { return false; }
00146 virtual void Select(bool b) {}
00148 virtual char *GetText(int Col=0) { return 0; }
00150 virtual bool SetText(char *s, int Col=0) { return false; }
00152 virtual int GetImage(int Flags = 0) { return -1; }
00154 virtual void SetImage(int Col) {}
00156 virtual GRect *GetPos(int Col = -1) { return 0; }
00158 virtual GFont *GetFont() { return 0; }
00160 virtual GViewFill *GetForegroundFill() { return _Fore; }
00162 virtual void SetForegroundFill(GViewFill *Fill) { _Fore.Reset(Fill); }
00164 virtual GViewFill *GetBackgroundFill() { return _Back; }
00166 virtual void SetBackgroundFill(GViewFill *Fill) { _Back.Reset(Fill); }
00167
00169 virtual bool XmlIo(class GXmlTag *Tag, bool Write) { return false; }
00170
00171 bool OnScriptEvent(GViewI *Ctrl) { return false; }
00172 int OnEvent(GMessage *Msg) { return 0; }
00173 void OnMouseEnter(GMouse &m) {}
00174 void OnMouseExit(GMouse &m) {}
00175 void OnMouseMove(GMouse &m) {}
00176 void OnMouseWheel(double Lines) {}
00177 bool OnKey(GKey &k) { return false; }
00178 void OnAttach() {}
00179 void OnCreate() {}
00180 void OnDestroy() {}
00181 void OnFocus(bool f) {}
00182 void OnPulse() {}
00183 void OnPosChange() {}
00184 bool OnRequestClose(bool OsShuttingDown) { return false; }
00185 int OnHitTest(int x, int y) { return 0; }
00186 void OnChildrenChanged(GViewI *Wnd, bool Attaching) {}
00187 int OnNotify(GViewI *Ctrl, int Flags) { return 0; }
00188 int OnCommand(int Cmd, int Event, OsView Wnd) { return 0; }
00189 void OnPaint(GSurface *pDC) { LgiAssert(0); }
00190 };
00191
00193 class GItemEdit : public GPopup
00194 {
00195 class GItemEditPrivate *d;
00196
00197 public:
00198 GItemEdit(GView *parent, GItem *item, int index, int selstart, int selend);
00199 ~GItemEdit();
00200
00201 void OnPaint(GSurface *pDC);
00202 int OnNotify(GViewI *v, int f);
00203 void Visible(bool i);
00204 int OnEvent(GMessage *Msg);
00205 };
00206
00209 #define GLI_MARK_NONE 0
00212 #define GLI_MARK_UP_ARROW 1
00215 #define GLI_MARK_DOWN_ARROW 2
00216
00218 class LgiClass GListColumn
00219 : public ResObject
00220 {
00221 class GListColumnPrivate *d;
00222 friend class GDragColumn;
00223 friend class GListItem;
00224 friend class GList;
00225
00226 public:
00227 GListColumn(GList *parent, char *name, int width);
00228 virtual ~GListColumn();
00229
00230
00231
00233 void Name(char *n);
00235 char *Name();
00237 void Width(int i);
00239 int Width();
00243 void Type(int i);
00245 int Type();
00247 void Mark(int i);
00249 int Mark();
00251 void Icon(GSurface *i, bool Own = true);
00253 GSurface *Icon();
00255 int Value();
00256
00258 void Image(int i);
00260 int Image();
00262 bool Resizable();
00264 void Resizable(bool i);
00265
00267 int GetIndex();
00269 int GetContentSize();
00271 GList *GetList();
00272
00274 void OnPaint(GSurface *pDC, GRect &r);
00275
00277 void OnPaint_Content(GSurface *pDC, GRect &r, bool FillBackground);
00278 };
00279
00280 class LgiClass GListItemPainter
00281 {
00282 public:
00283
00284 virtual void OnPaintColumn(GItem::ItemPaintCtx &Ctx, int i, GListColumn *c) = 0;
00285 };
00286
00287 class LgiClass GListItemColumn : public GBase, public GItem, public GListItemPainter
00288 {
00289 GListItem *_Item;
00290 int _Column;
00291 int _Value;
00292
00293 void OnPaint(ItemPaintCtx &Ctx) {}
00294
00295 protected:
00296 List<GListItem> *GetAllItems();
00297 GListItemColumn *GetItemCol(GListItem *i, int Col);
00298
00299 public:
00300 GListItemColumn(GListItem *item, int col);
00301
00302
00303 GListItem *GetItem() { return _Item; }
00304 GList *GetList();
00305
00306
00307 int GetColumn() { return _Column; }
00308 void SetColumn(int i) { _Column = i; }
00309 virtual int64 Value() { return _Value; }
00310 virtual void Value(int64 i);
00311 };
00312
00314 class LgiClass GListItem : public GItem, public GListItemPainter
00315 {
00316 friend class GList;
00317 friend class GListItemColumn;
00318 friend class GListColumn;
00319
00320 void OnEditLabelEnd();
00321
00322 protected:
00323
00324 class GListItemPrivate *d;
00325 GRect Pos;
00326 GList *Parent;
00327
00328
00329 bool GridLines();
00330 GDisplayString *GetDs(int Col, int FitTo = -1);
00331
00332 public:
00333
00334 void *_UserData;
00335
00336
00337 GListItem();
00338 virtual ~GListItem();
00339
00341 GList *GetList() { return Parent; }
00343 List<GListItemColumn> *GetItemCols();
00344
00345
00346
00348 bool SetText(char *s, int i=0);
00349
00357 char *GetText
00358 (
00360 int i
00361 );
00362
00365 int GetImage(int Flags = 0);
00367 void SetImage(int i);
00369 bool Select();
00371 void Select(bool b);
00373 GRect *GetPos(int Col = -1);
00375 bool OnScreen() { return Pos.y1 < Pos.y2; }
00376
00377
00378
00380 void Update();
00382 void ScrollTo();
00384 void SetEditLabelSelection(int SelStart, int SelEnd);
00386 GView *EditLabel(int Col = -1);
00387
00388
00389 void OnMouseClick(GMouse &m);
00390 void OnMeasure(GMeasureInfo *Info);
00391 void OnPaint(GSurface *pDC) { LgiAssert(0); }
00392 void OnPaint(GItem::ItemPaintCtx &Ctx);
00393 void OnPaintColumn(GItem::ItemPaintCtx &Ctx, int i, GListColumn *c);
00394
00395
00396 virtual int Compare(GListItem *To, int Field) { return 0; }
00397 virtual void OnColumnNotify(int Col, int Data) {}
00398 };
00399
00400 typedef int (*GListCompareFunc)(GListItem *a, GListItem *b, int Data);
00401
00402 class GListItems
00403 {
00404 protected:
00405 List<GListItem> Items;
00406
00407 public:
00408 template<class T>
00409 bool GetSelection(List<T> &n)
00410 {
00411 n.Empty();
00412 List<GListItem>::I It = Items.Start();
00413 for (GListItem *i=*It; i; i=*++It)
00414 {
00415 if (i->Select())
00416 n.Insert(dynamic_cast<T*>(i));
00417 }
00418 return n.Length() > 0;
00419 }
00420
00421 template<class T>
00422 bool GetAll(List<T> &n)
00423 {
00424 n.Empty();
00425 List<GListItem>::I It = Items.Start();
00426 for (GListItem *i=*It; i; i=*++It)
00427 {
00428 n.Insert(dynamic_cast<T*>(i));
00429 }
00430 return n.Length() > 0;
00431 }
00432
00433 List<GListItem>::I Start()
00434 {
00435 return Items.Start();
00436 }
00437
00438 List<GListItem>::I End()
00439 {
00440 return Items.End();
00441 }
00442 };
00443
00445 class LgiClass GList :
00446 public GLayout,
00447 public GItemContainer,
00448 public ResObject,
00449 public GListItems
00450 {
00451 friend class GListItem;
00452 friend class GListColumn;
00453 friend class GListItemColumn;
00454
00455 #ifdef WIN32
00456 HCURSOR Cursor;
00457 #endif
00458
00459 protected:
00460 class GListPrivate *d;
00461
00462
00463 List<GListColumn> Columns;
00464 int Keyboard;
00465
00466
00467 bool ColumnHeaders;
00468 bool EditLabels;
00469 bool GridLines;
00470 bool MultiItemSelect;
00471
00472
00473 GSurface *Buf;
00474
00475
00476 GRect ItemsPos;
00477 GRect ColumnHeader;
00478 GRect ScrollX, ScrollY;
00479 int FirstVisible;
00480 int LastVisible;
00481 int CompletelyVisible;
00482 GListColumn *IconCol;
00483
00484
00485 bool GetUpdateRegion(GListItem *i, GRegion &r);
00486 GListItem *HitItem(int x, int y, int *Index = 0);
00487 GRect &GetClientRect();
00488 void Pour();
00489 void UpdateScrollBars();
00490 void KeyScroll(int iTo, int iFrom, bool SelectItems);
00491 int HitColumn(int x, int y, GListColumn *&Resize, GListColumn *&Over);
00492
00493 public:
00495 GList
00496 (
00498 int id,
00500 int x,
00502 int y,
00504 int cx,
00506 int cy,
00508 char *name = "List"
00509 );
00510 ~GList();
00511
00512 char *GetClass() { return "GList"; }
00513
00514
00515
00517 virtual void OnItemClick
00518 (
00520 GListItem *Item,
00522 GMouse &m
00523 );
00525 virtual void OnItemBeginDrag
00526 (
00528 GListItem *Item,
00530 GMouse &m
00531 );
00535 virtual void OnItemSelect
00536 (
00538 GArray<GListItem*> &Items
00539 );
00541 virtual void OnColumnClick
00542 (
00544 int Col,
00546 GMouse &m
00547 );
00549 virtual void OnColumnDrag
00550 (
00552 int Col,
00554 GMouse &m
00555 ) {}
00558 virtual bool OnColumnReindex
00559 (
00561 GListColumn *Col,
00563 int OldIndex,
00565 int NewIndex
00566 )
00567 {
00568 return false;
00569 }
00570
00571
00572
00573 void OnPaint(GSurface *pDC);
00574 int OnEvent(GMessage *Msg);
00575 int OnHitTest(int x, int y);
00576 void OnMouseClick(GMouse &m);
00577 void OnMouseMove(GMouse &m);
00578 int OnNotify(GViewI *Ctrl, int Flags);
00579 void OnPosChange();
00580 bool OnKey(GKey &k);
00581 void OnMouseWheel(double Lines);
00582 void OnFocus(bool b);
00583 void OnPulse();
00584
00585
00586
00588 GListColumn *AddColumn
00589 (
00591 char *Name,
00593 int Width = 50,
00595 int Where = -1
00596 );
00598 bool AddColumn
00599 (
00601 GListColumn *Col,
00603 int Where = -1
00604 );
00606 bool DeleteColumn(GListColumn *Col);
00608 void EmptyColumns();
00610 GListColumn *ColumnAt(int Index) { return Columns.ItemAt(Index); }
00612 int ColumnAtX(int X, GListColumn **Col = 0, int *Offset = 0);
00614 int GetColumns() { return Columns.Length(); }
00617 void DragColumn(int Index);
00619 bool GetColumnClickInfo(int &Col, GMouse &m);
00620
00621
00622
00624 bool ShowColumnHeader() { return ColumnHeaders; }
00626 void ShowColumnHeader(bool Show) { ColumnHeaders = Show; }
00628 bool AllowEditLabels() { return EditLabels; }
00630 void AllowEditLabels(bool b) { EditLabels = b; }
00632 bool DrawGridLines() { return GridLines; }
00634 void DrawGridLines(bool b) { GridLines = b; }
00636 bool MultiSelect() { return MultiItemSelect; }
00638 void MultiSelect(bool b) { MultiItemSelect = b; }
00639
00640
00641
00644 GListMode GetMode();
00647 void SetMode(GListMode m);
00648
00650 int64 Value();
00652 void Value(int64 i);
00654 bool Select(GListItem *Obj);
00656 GListItem *GetSelected();
00658 void SelectAll();
00660 void ScrollToSelection();
00662 void UpdateAllItems();
00664 int Length() { return Items.Length(); }
00665
00667 bool IsEmpty() { return Items.Length() == 0; }
00669 bool Delete();
00671 bool Delete(int Index);
00673 bool Delete(GListItem *p);
00675 bool Insert
00676 (
00678 GListItem *p,
00680 int Index = -1,
00683 bool Update = true
00684 );
00686 bool Insert
00687 (
00689 List<GListItem> &l,
00691 int Index = -1,
00694 bool Update = true
00695 );
00697 bool Remove(GListItem *Obj);
00699 bool HasItem(GListItem *Obj);
00701 int IndexOf(GListItem *Obj);
00703 GListItem *ItemAt(int Index);
00705 void Sort
00706 (
00708 GListCompareFunc Compare,
00710 int Data
00711 );
00712
00714 void Empty();
00716 void RemoveAll();
00718 void ResizeColumnsToContent(int Border = DEFAULT_COLUMN_SPACING);
00719 };
00720
00721 #endif