52 const TGFont *TGTextLBEntry::fgDefaultFont = 0;
53 TGGC *TGTextLBEntry::fgDefaultGC = 0;
56 ClassImp(TGTextLBEntry);
57 ClassImp(TGLineLBEntry);
58 ClassImp(TGLBContainer);
64 TGLBEntry::TGLBEntry(
const TGWindow *p, Int_t
id, UInt_t options, Pixel_t back) :
65 TGFrame(p, 10, 10, options | kOwnBackground, back)
70 fEditDisabled = kEditDisable | kEditDisableGrab;
78 void TGLBEntry::Activate(Bool_t a)
80 if (fActive == a)
return;
88 void TGLBEntry::Toggle()
107 TGTextLBEntry::TGTextLBEntry(
const TGWindow *p, TGString *s, Int_t
id,
108 GContext_t norm, FontStruct_t font, UInt_t options, ULong_t back) :
109 TGLBEntry(p, id, options, back)
112 fTextChanged = kTRUE;
117 int max_ascent, max_descent;
119 if (fText) fTWidth = gVirtualX->TextWidth(fFontStruct, fText->GetString(), fText->GetLength());
120 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
121 fTHeight = max_ascent + max_descent;
122 Resize(fTWidth, fTHeight + 1);
123 fEditDisabled = kEditDisable | kEditDisableGrab;
130 TGTextLBEntry::~TGTextLBEntry()
132 if (fText)
delete fText;
138 void TGTextLBEntry::DrawCopy(Handle_t
id, Int_t x, Int_t y)
140 int max_ascent, max_descent;
142 y += (fHeight - fTHeight) >> 1;
144 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
147 gVirtualX->SetForeground(fNormGC, fgDefaultSelectedBackground );
148 gVirtualX->FillRectangle(
id,fNormGC, x, y, fWidth, fHeight);
149 gVirtualX->SetForeground(fNormGC, fClient->GetResourcePool()->GetSelectedFgndColor());
150 fText->Draw(
id, fNormGC, x + 3, y + max_ascent);
152 gVirtualX->SetForeground(fNormGC, fBkcolor);
153 gVirtualX->FillRectangle(
id, fNormGC, x, y, fWidth, fHeight);
154 gVirtualX->SetForeground(fNormGC, GetForeground());
155 fText->Draw(
id, fNormGC, x + 3, y + max_ascent);
162 void TGTextLBEntry::DoRedraw()
164 if (fId) DrawCopy(fId, 0, 0);
170 void TGTextLBEntry::SetText(TGString *new_text)
172 if (fText)
delete fText;
174 fTextChanged = kTRUE;
176 int max_ascent, max_descent;
177 fTWidth = gVirtualX->TextWidth(fFontStruct, fText->GetString(), fText->GetLength());
178 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
179 fTHeight = max_ascent + max_descent;
181 Resize(fTWidth + 3, fTHeight + 1);
189 FontStruct_t TGTextLBEntry::GetDefaultFontStruct()
192 fgDefaultFont = gClient->GetResourcePool()->GetDefaultFont();
193 return fgDefaultFont->GetFontStruct();
199 const TGGC &TGTextLBEntry::GetDefaultGC()
202 fgDefaultGC =
new TGGC(*gClient->GetResourcePool()->GetFrameGC());
217 TGLineLBEntry::TGLineLBEntry(
const TGWindow *p, Int_t
id,
const char *str,
218 UInt_t w, Style_t style, UInt_t options, ULong_t back) :
219 TGTextLBEntry(p, new TGString(str), id, GetDefaultGC()(),
220 GetDefaultFontStruct(), options, back)
224 gcv.fMask = kGCLineStyle | kGCLineWidth | kGCFillStyle | kGCDashList;
225 fLineWidth = gcv.fLineWidth = w;
226 gcv.fFillStyle = kFillSolid;
229 memcpy(gcv.fDashes,
"\x5\x5", 3);
230 gcv.fLineStyle = kLineOnOffDash;
231 fLineGC = fClient->GetGC(&gcv, kTRUE);
234 int max_ascent, max_descent;
236 fTWidth = gVirtualX->TextWidth(GetDefaultFontStruct(),
"8", 1);
238 gVirtualX->GetFontProperties(GetDefaultFontStruct(),
239 max_ascent, max_descent);
240 fTHeight = max_ascent + max_descent;
243 Resize(fTWidth, fTHeight + 1);
244 fEditDisabled = kEditDisable | kEditDisableGrab;
251 TGLineLBEntry::~TGLineLBEntry()
253 fClient->FreeGC(fLineGC);
259 void TGLineLBEntry::Update(TGLBEntry *e)
261 TGTextLBEntry::Update(e);
263 fClient->FreeGC(fLineGC);
264 fLineGC = ((TGLineLBEntry *)e)->GetLineGC();
265 fLineGC->AddReference();
271 void TGLineLBEntry::SetLineStyle(Style_t linestyle)
273 static const char* dashed =
"\x3\x3";
274 static const char* dotted=
"\x1\x2";
275 static const char* dasheddotted =
"\x3\x4\x1\x4";
276 static const char* ls05 =
"\x5\x3\x1\x3";
277 static const char* ls06 =
"\x5\x3\x1\x3\x1\x3\x1\x3";
278 static const char* ls07 =
"\x5\x5";
279 static const char* ls08 =
"\x5\x3\x1\x3\x1\x3";
280 static const char* ls09 =
"\x20\x5";
281 static const char* ls10 =
"\x20\x10\x1\x10";
284 if (linestyle <= 1) {
285 fLineGC->SetLineStyle(kLineSolid);
289 fLineGC->SetDashList(dashed, 2);
292 fLineGC->SetDashList(dotted, 2);
295 fLineGC->SetDashList(dasheddotted, 4);
298 fLineGC->SetDashList(ls05, 4);
301 fLineGC->SetDashList(ls06, 8);
304 fLineGC->SetDashList(ls07, 2);
307 fLineGC->SetDashList(ls08, 6);
310 fLineGC->SetDashList(ls09, 2);
313 fLineGC->SetDashList(ls10, 4);
317 fLineGC->SetCapStyle(0);
318 fLineStyle = linestyle;
324 void TGLineLBEntry::SetLineWidth(Int_t width)
327 fLineGC->SetLineWidth(fLineWidth);
333 void TGLineLBEntry::DrawCopy(Handle_t
id, Int_t x, Int_t y)
335 TGTextLBEntry::DrawCopy(
id, x, y);
336 if (!strcmp(TGTextLBEntry::GetTitle(),
"None"))
return;
338 gVirtualX->SetForeground(fLineGC->GetGC(),
339 fClient->GetResourcePool()->GetSelectedFgndColor());
341 gVirtualX->SetForeground(fLineGC->GetGC(),
342 fClient->GetResourcePool()->GetBlackColor());
344 gVirtualX->DrawLine(
id, fLineGC->GetGC(), x + fTWidth + 5, y + fHeight/2,
345 x + fWidth - 5, y + fHeight/2);
351 void TGLineLBEntry::DoRedraw()
353 if (fId) DrawCopy(fId, 0, 0);
367 TGIconLBEntry::TGIconLBEntry(
const TGWindow *p, Int_t
id,
const char *str,
368 const TGPicture *pic,
369 UInt_t , Style_t , UInt_t options, ULong_t back) :
370 TGTextLBEntry(p, new TGString(str), id, GetDefaultGC()(),
371 GetDefaultFontStruct(), options, back)
373 int max_ascent, max_descent;
377 fTWidth += fPicture->GetWidth() + 4;
378 ((TGPicture *)fPicture)->AddReference();
382 gVirtualX->GetFontProperties(GetDefaultFontStruct(),
383 max_ascent, max_descent);
384 fTHeight = max_ascent + max_descent;
385 if (fPicture && fPicture->GetHeight() > fTHeight)
386 fTHeight = fPicture->GetHeight();
388 Resize(fTWidth, fTHeight + 1);
389 fEditDisabled = kEditDisable | kEditDisableGrab;
396 TGIconLBEntry::~TGIconLBEntry()
398 fClient->FreePicture(fPicture);
404 void TGIconLBEntry::Update(TGLBEntry *e)
406 TGTextLBEntry::Update(e);
412 void TGIconLBEntry::DrawCopy(Handle_t
id, Int_t x, Int_t y)
416 fPicture->Draw(
id, fNormGC, x + 2, y);
417 off_x = fPicture->GetWidth() + 4;
419 TGTextLBEntry::DrawCopy(
id, x + off_x, y);
425 void TGIconLBEntry::DoRedraw()
427 if (fId) DrawCopy(fId, 0, 0);
433 void TGIconLBEntry::SetPicture(
const TGPicture *pic)
435 fClient->FreePicture(fPicture);
437 if (pic) ((TGPicture *)pic)->AddReference();
443 class TGLBFrameElement :
public TGFrameElement {
445 TGLBFrameElement(TGFrame *f, TGLayoutHints *l) : TGFrameElement(f, l) {}
446 virtual ~TGLBFrameElement() {}
448 Bool_t IsSortable()
const {
return kTRUE; }
449 Int_t Compare(
const TObject *obj)
const {
450 if (!fFrame->InheritsFrom(TGTextLBEntry::Class())) {
453 TGTextLBEntry *f1 = (TGTextLBEntry*)fFrame;
454 TGTextLBEntry *f2 = (TGTextLBEntry *) ((TGFrameElement *) obj)->fFrame;
458 const char *t1 = f1->GetText()->Data();
459 const char *t2 = f2->GetText()->Data();
461 if ((d1 = atof(t1)) && (d2 = atof(t2))) {
464 return strcmp(t1, t2);
482 TGLBContainer::TGLBContainer(
const TGWindow *p, UInt_t w, UInt_t h,
483 UInt_t options, ULong_t back) :
484 TGContainer(p, w, h, options, back)
488 fMultiSelect = kFALSE;
489 fChangeStatus = kFALSE;
493 fEditDisabled = kEditDisableGrab | kEditDisableBtnEnable | kEditDisableKeyEnable;
499 TGLBContainer::~TGLBContainer()
507 void TGLBContainer::Layout()
509 TGContainer::Layout();
510 TGFrame::Resize(fListBox->GetViewPort()->GetWidth(), fHeight);
516 void TGLBContainer::DoRedraw()
518 return TGContainer::DoRedraw();
525 void TGLBContainer::AddEntry(TGLBEntry *lbe, TGLayoutHints *lhints)
530 TGLBFrameElement *nw =
new TGLBFrameElement(lbe, lhints ? lhints : fgDefaultHints);
540 void TGLBContainer::InsertEntry(TGLBEntry *lbe, TGLayoutHints *lhints, Int_t afterID)
546 TGFrameElement *el, *nw;
549 while ((el = (TGFrameElement *) next())) {
550 e = (TGLBEntry *) el->fFrame;
551 if (e->EntryId() == afterID)
break;
554 if (!el && afterID != -1) {
555 nw =
new TGLBFrameElement(lbe, lhints ? lhints : fgDefaultHints);
558 nw =
new TGLBFrameElement(lbe, lhints);
560 nw->fLayout = lhints;
567 fList->AddAfter(el, nw);
576 void TGLBContainer::AddEntrySort(TGLBEntry *lbe, TGLayoutHints *lhints)
582 TGFrameElement *el, *nw;
585 while ((el = (TGFrameElement *) next())) {
586 e = (TGLBEntry *) el->fFrame;
587 if (e->EntryId() > lbe->EntryId())
break;
591 nw =
new TGLBFrameElement(lbe, lhints ? lhints : fgDefaultHints);
594 nw =
new TGLBFrameElement(lbe, lhints);
596 nw->fLayout = lhints;
600 fList->AddBefore(el, nw);
609 void TGLBContainer::RemoveEntry(Int_t
id)
617 while ((el = (TGFrameElement *) next())) {
618 e = (TGLBEntry *) el->fFrame;
620 if (e->EntryId() == id) {
621 if (fLastActive == e) fLastActive = 0;
637 void TGLBContainer::RemoveEntries(Int_t from_ID, Int_t to_ID)
645 while ((el = (TGFrameElement *) next())) {
646 e = (TGLBEntry *) el->fFrame;
648 if ((e->EntryId() >= from_ID) && (e->EntryId() <= to_ID)) {
649 if (fLastActive == e) fLastActive = 0;
663 void TGLBContainer::RemoveAll()
671 while ((el = (TGFrameElement *) next())) {
672 e = (TGLBEntry *) el->fFrame;
674 if (fLastActive == e) fLastActive = 0;
688 TGLBEntry *TGLBContainer::Select(Int_t
id)
690 return Select(
id, kTRUE);
697 TGLBEntry *TGLBContainer::Select(Int_t
id, Bool_t sel)
702 if (!fMultiSelect && fLastActive) {
703 fLastActive->Activate(kFALSE);
708 while ((el = (TGFrameElement *) next())) {
709 f = (TGLBEntry *) el->fFrame;
710 if (f->EntryId() == id) {
712 if (fMultiSelect == kFALSE && sel == kTRUE) {
728 Int_t TGLBContainer::GetSelected()
const
730 if (fLastActive == 0)
return -1;
731 return fLastActive->EntryId();
737 Bool_t TGLBContainer::GetSelection(Int_t
id)
743 while ((el = (TGFrameElement *) next())) {
744 f = (TGLBEntry *) el->fFrame;
745 if (f->EntryId() == id)
746 return f->IsActive();
756 void TGLBContainer::GetSelectedEntries(TList *selected)
762 while ((el = (TGFrameElement *) next())) {
763 f = (TGLBEntry *) el->fFrame;
773 void TGLBContainer::SetMultipleSelections(Bool_t multi)
777 fMultiSelect = multi;
781 while ((el = (TGFrameElement *) next())) {
782 ((TGLBEntry *)(el->fFrame))->Activate(kFALSE);
793 TGVScrollBar *TGLBContainer::GetVScrollbar()
const
795 return fListBox ? fListBox->GetVScrollbar() : 0;
801 void TGLBContainer::SetVsbPosition(Int_t newPos)
803 TGVScrollBar *vb = GetVScrollbar();
805 if (vb && vb->IsMapped()) {
806 vb->SetPosition(newPos);
813 Bool_t TGLBContainer::HandleButton(Event_t *event)
815 int xf0, yf0, xff, yff;
819 TGLBEntry *last = fLastActive;
821 TGPosition pos = GetPagePosition();
822 Int_t x = pos.fX +
event->fX;
823 Int_t y = pos.fY +
event->fY;
824 Bool_t activate = kFALSE;
827 if (fClient->IsEditable() && (
event->fCode == kButton3)) {
831 TGVScrollBar *vb = GetVScrollbar();
833 if ((event->fCode == kButton4) && vb){
835 Int_t newpos = vb->GetPosition() - 1;
836 if (newpos < 0) newpos = 0;
837 vb->SetPosition(newpos);
841 if ((event->fCode == kButton5) && vb) {
843 Int_t newpos = vb->GetPosition() + 1;
844 vb->SetPosition(newpos);
849 gVirtualX->SetInputFocus(fId);
852 if (event->fType == kButtonPress) {
854 while ((el = (TGFrameElement *) next())) {
855 f = (TGLBEntry *) el->fFrame;
858 xff = xf0 + f->GetWidth();
859 yff = yf0 + f->GetHeight();
861 activate = fMapSubwindows ? (f->GetId() == (Window_t)event->fUser[0]) :
862 (x > xf0) && (x < xff) && (y > yf0) && (y < yff);
868 fChangeStatus = f->IsActive() ? 1 : 0;
869 SendMessage(fMsgWindow, MK_MSG(kC_CONTAINER, kCT_ITEMCLICK),
878 if (event->fType == kButtonPress) {
880 fLastActive->Activate(kFALSE);
884 while ((el = (TGFrameElement *) next())) {
885 f = (TGLBEntry *) el->fFrame;
888 xff = xf0 + f->GetWidth();
889 yff = yf0 + f->GetHeight();
891 activate = fMapSubwindows ? (f->GetId() == (Window_t)event->fUser[0]) :
892 (x > xf0) && (x < xff) && (y > yf0) && (y < yff) && !f->IsActive();
905 SendMessage(fMsgWindow, MK_MSG(kC_CONTAINER, kCT_ITEMCLICK),
910 if (event->fType == kButtonRelease) {
912 gSystem->RemoveTimer(fScrollTimer);
914 if (fChangeStatus || (last != fLastActive))
918 if (fListBox->GetParent()->InheritsFrom(
"TGComboBoxPopup"))
919 fListBox->GetContainer()->RemoveInput(kPointerMotionMask);
926 Bool_t TGLBContainer::HandleDoubleClick(Event_t *ev)
930 TGLBEntry *f = fLastActive;
931 SendMessage(fMsgWindow, MK_MSG(kC_CONTAINER, kCT_ITEMDBLCLICK),
933 DoubleClicked(f, ev->fCode);
934 DoubleClicked(f, ev->fCode, ev->fXRoot, ev->fYRoot);
938 return TGContainer::HandleDoubleClick(ev);
944 Bool_t TGLBContainer::HandleMotion(Event_t *event)
946 int xf0, yf0, xff, yff;
948 static Long64_t was = gSystem->Now();
949 Long64_t now = gSystem->Now();
951 if ((now-was) < 50)
return kFALSE;
956 TGPosition pos = GetPagePosition();
957 TGDimension dim = GetPageDimension();
958 Int_t x = pos.fX +
event->fX;
959 Int_t y = pos.fY +
event->fY;
960 Bool_t activate = kFALSE;
961 TGLBEntry *last = fLastActive;
965 if ((event->fY < 10) || (event->fY > Int_t(dim.fHeight) - 10)) {
967 fScrollTimer->Reset();
968 gSystem->AddTimer(fScrollTimer);
972 else if (fChangeStatus >= 0) {
974 while ((el = (TGFrameElement *) next())) {
975 f = (TGLBEntry *) el->fFrame;
978 xff = xf0 + f->GetWidth();
979 yff = yf0 + f->GetHeight();
980 activate = fMapSubwindows ? (f->GetId() == (Window_t)event->fUser[0]) :
981 (x > xf0) && (x < xff) && (y > yf0) && (y < yff);
984 if (fChangeStatus != (f->IsActive() ? 1 : 0)) {
987 SendMessage(fMsgWindow, MK_MSG(kC_CONTAINER, kCT_ITEMCLICK),
994 }
else if (fListBox->GetParent()->InheritsFrom(
"TGComboBoxPopup")) {
996 while ((el = (TGFrameElement *) next())) {
997 f = (TGLBEntry *) el->fFrame;
1000 xff = xf0 + f->GetWidth();
1001 yff = yf0 + f->GetHeight();
1003 activate = fMapSubwindows ? (f->GetId() == (Window_t)event->fUser[0]) :
1004 (x > xf0) && (x < xff) && (y > yf0) && (y < yff) && !f->IsActive();
1011 f->Activate(kFALSE);
1013 if (last != fLastActive) {
1024 void TGLBContainer::OnAutoScroll()
1026 TGFrameElement* el = 0;
1029 Bool_t changed = kFALSE;
1031 TGDimension dim = GetPageDimension();
1032 TGPosition pos = GetPagePosition();
1034 Window_t dum1, dum2;
1036 ev.fType = kButtonPress;
1040 gVirtualX->QueryPointer(fId,dum1,dum2,ev.fXRoot,ev.fYRoot,x,y,ev.fState);
1041 TGVScrollBar *vb = GetVScrollbar();
1042 if (vb && y > 0 && y < 10) {
1044 Int_t newpos = vb->GetPosition() - 1;
1045 if (newpos < 0) newpos = 0;
1046 vb->SetPosition(newpos);
1049 else if (vb && y > (Int_t)dim.fHeight - 10 && y < (Int_t)dim.fHeight) {
1051 Int_t newpos = vb->GetPosition() + 1;
1052 vb->SetPosition(newpos);
1055 if (changed && fChangeStatus >= 0) {
1056 pos = GetPagePosition();
1058 while ((el = (TGFrameElement *) next())) {
1059 f = (TGLBEntry *) el->fFrame;
1061 yff = yf0 + f->GetHeight();
1062 if ((y + pos.fY > yf0) && (y + pos.fY < yff)) {
1063 if (fChangeStatus != (f->IsActive() ? 1 : 0)) {
1066 SendMessage(fMsgWindow, MK_MSG(kC_CONTAINER, kCT_ITEMCLICK),
1078 void TGLBContainer::ActivateItem(TGFrameElement *el)
1080 TGContainer::ActivateItem(el);
1081 fLastActive = (TGLBEntry *)el->fFrame;
1089 Int_t TGLBContainer::GetPos(Int_t
id)
1096 while ((el = (TGFrameElement *) next())) {
1097 f = (TGLBEntry *) el->fFrame;
1098 if (f->EntryId() == id)
1123 TGListBox::TGListBox(
const TGWindow *p, Int_t
id,
1124 UInt_t options, ULong_t back) :
1125 TGCompositeFrame(p, 10, 10, options, back)
1131 fIntegralHeight = kTRUE;
1139 TGListBox::~TGListBox()
1141 if (!MustCleanup()) {
1151 void TGListBox::InitListBox()
1153 fVport =
new TGViewPort(
this, 6, 6, kChildFrame | kOwnBackground, fgWhitePixel);
1154 fVScrollbar =
new TGVScrollBar(
this, kDefaultScrollBarWidth, 6);
1155 fLbc =
new TGLBContainer(fVport, 10, 10, kVerticalFrame, fgWhitePixel);
1156 fLbc->fViewPort = fVport;
1157 fLbc->Associate(
this);
1158 fLbc->SetListBox(
this);
1161 AddFrame(fVport, 0);
1162 AddFrame(fVScrollbar, 0);
1164 fVScrollbar->Associate(
this);
1166 fVScrollbar->AddInput(kButtonPressMask | kButtonReleaseMask |
1167 kPointerMotionMask);
1168 fLbc->RemoveInput(kPointerMotionMask);
1169 fLbc->AddInput(kButtonPressMask | kButtonReleaseMask | kButtonMotionMask);
1171 fVport->SetEditDisabled(kEditDisable | kEditDisableGrab);
1172 fVScrollbar->SetEditDisabled(kEditDisable | kEditDisableGrab | kEditDisableBtnEnable);
1173 fLbc->SetEditDisabled(kEditDisableGrab | kEditDisableBtnEnable | kEditDisableKeyEnable);
1174 fEditDisabled = kEditDisableLayout;
1177 delete fLayoutManager;
1184 void TGListBox::DrawBorder()
1186 switch (fOptions & (kSunkenFrame | kRaisedFrame | kDoubleBorder)) {
1188 case kSunkenFrame | kDoubleBorder:
1189 gVirtualX->DrawLine(fId, GetShadowGC()(), 0, 0, fWidth-2, 0);
1190 gVirtualX->DrawLine(fId, GetShadowGC()(), 0, 0, 0, fHeight-2);
1191 gVirtualX->DrawLine(fId, GetBlackGC()(), 1, 1, fWidth-3, 1);
1192 gVirtualX->DrawLine(fId, GetBlackGC()(), 1, 1, 1, fHeight-3);
1193 if (gClient->GetStyle() > 1)
break;
1194 gVirtualX->DrawLine(fId, GetHilightGC()(), 0, fHeight-1, fWidth-1, fHeight-1);
1195 gVirtualX->DrawLine(fId, GetHilightGC()(), fWidth-1, fHeight-1, fWidth-1, 0);
1196 gVirtualX->DrawLine(fId, GetBckgndGC()(), 1, fHeight-2, fWidth-2, fHeight-2);
1197 gVirtualX->DrawLine(fId, GetBckgndGC()(), fWidth-2, 1, fWidth-2, fHeight-2);
1201 TGCompositeFrame::DrawBorder();
1211 void TGListBox::AddEntry(TGString *s, Int_t
id)
1214 TGLayoutHints *lhints;
1216 lbe =
new TGTextLBEntry(fLbc, s,
id);
1217 lhints =
new TGLayoutHints(kLHintsExpandX | kLHintsTop);
1218 fItemVsize = TMath::Max(fItemVsize, lbe->GetDefaultHeight());
1219 fLbc->AddEntry(lbe, lhints);
1226 void TGListBox::AddEntry(
const char *s, Int_t
id)
1228 AddEntry(
new TGString(s),
id);
1235 void TGListBox::AddEntry(TGLBEntry *lbe, TGLayoutHints *lhints)
1237 fItemVsize = TMath::Max(fItemVsize, lbe->GetDefaultHeight());
1238 fLbc->AddEntry(lbe, lhints);
1248 void TGListBox::AddEntrySort(TGString *s, Int_t
id)
1251 TGLayoutHints *lhints;
1253 lbe =
new TGTextLBEntry(fLbc, s,
id);
1254 lhints =
new TGLayoutHints(kLHintsExpandX | kLHintsTop);
1255 fItemVsize = TMath::Max(fItemVsize, lbe->GetDefaultHeight());
1256 fLbc->AddEntrySort(lbe, lhints);
1265 void TGListBox::AddEntrySort(
const char *s, Int_t
id)
1267 AddEntrySort(
new TGString(s),
id);
1276 void TGListBox::AddEntrySort(TGLBEntry *lbe, TGLayoutHints *lhints)
1278 fItemVsize = TMath::Max(fItemVsize, lbe->GetDefaultHeight());
1279 fLbc->AddEntrySort(lbe, lhints);
1286 void TGListBox::InsertEntry(TGString *s, Int_t
id, Int_t afterID)
1289 TGLayoutHints *lhints;
1291 lbe =
new TGTextLBEntry(fLbc, s,
id);
1292 lhints =
new TGLayoutHints(kLHintsExpandX | kLHintsTop);
1293 fItemVsize = TMath::Max(fItemVsize, lbe->GetDefaultHeight());
1294 fLbc->InsertEntry(lbe, lhints, afterID);
1300 void TGListBox::InsertEntry(
const char *s, Int_t
id, Int_t afterID)
1302 InsertEntry(
new TGString(s),
id, afterID);
1308 void TGListBox::NewEntry(
const char *s)
1310 Int_t selected = fLbc->GetSelected();
1313 if ((selected < 0) || (selected == GetNumberOfEntries())) {
1314 AddEntry(s, GetNumberOfEntries()+1);
1316 InsertEntry(s, GetNumberOfEntries()+1, selected);
1326 void TGListBox:: RemoveEntry(Int_t
id)
1329 fLbc->RemoveEntry(
id);
1333 if (!fLbc->GetMultipleSelections()) {
1334 fLbc->RemoveEntry(fLbc->GetSelected());
1339 fLbc->GetSelectedEntries(&li);
1343 while ((e = (TGLBEntry*)next())) {
1344 fLbc->RemoveEntry(e->EntryId());
1352 void TGListBox::RemoveAll()
1361 void TGListBox::RemoveEntries(Int_t from_ID, Int_t to_ID)
1363 fLbc->RemoveEntries(from_ID, to_ID);
1371 void TGListBox::InsertEntry(TGLBEntry *lbe, TGLayoutHints *lhints,
int afterID)
1373 fItemVsize = TMath::Max(fItemVsize, lbe->GetDefaultHeight());
1374 fLbc->InsertEntry(lbe, lhints, afterID);
1380 TGLBEntry *TGListBox::GetEntry(Int_t
id)
const
1382 TIter next(fLbc->GetList());
1385 while ((el = (TGFrameElement *)next())) {
1386 TGLBEntry *lbe = (TGLBEntry *)el->fFrame;
1387 if (lbe->EntryId() == id)
return lbe;
1395 void TGListBox::SetTopEntry(Int_t
id)
1399 idPos = fLbc->GetPos(
id);
1412 fVScrollbar->SetPosition(idPos);
1419 void TGListBox::Resize(UInt_t w, UInt_t h)
1421 if (fIntegralHeight)
1422 h = TMath::Max(fItemVsize, ((h - (fBorderWidth << 1)) / fItemVsize) * fItemVsize)
1423 + (fBorderWidth << 1);
1425 TGCompositeFrame::Resize(w, h);
1432 void TGListBox::MoveResize(Int_t x, Int_t y, UInt_t w, UInt_t h)
1434 if (fIntegralHeight)
1435 h = TMath::Max(fItemVsize, ((h - (fBorderWidth << 1)) / fItemVsize) * fItemVsize)
1436 + (fBorderWidth << 1);
1437 TGCompositeFrame::MoveResize(x, y, w, h);
1444 TGDimension TGListBox::GetDefaultSize()
const
1448 if (fIntegralHeight)
1449 h = TMath::Max(fItemVsize, ((fHeight - (fBorderWidth << 1)) / fItemVsize) * fItemVsize)
1450 + (fBorderWidth << 1);
1454 return TGDimension(fWidth, h);
1460 void TGListBox::Layout()
1468 container = fVport->GetContainer();
1472 cw = fWidth - (fBorderWidth << 1);
1473 ch = fHeight - (fBorderWidth << 1);
1475 container->SetWidth(cw);
1476 container->SetHeight(ch);
1478 if (container->GetDefaultHeight() > ch) {
1480 cw -= fVScrollbar->GetDefaultWidth();
1481 if ((Int_t) cw < 0) {
1482 Warning(
"Layout",
"width would become too small, setting to 10");
1485 container->SetWidth(cw);
1488 fVport->MoveResize(fBorderWidth, fBorderWidth, cw, ch);
1489 container->Layout();
1491 tch = TMath::Max(container->GetDefaultHeight(), ch);
1492 container->SetHeight(0);
1493 container->Resize(cw, tch);
1497 fVScrollbar->MoveResize(cw+fBorderWidth, fBorderWidth, fVScrollbar->GetDefaultWidth(), ch);
1498 fVScrollbar->MapWindow();
1500 fVScrollbar->UnmapWindow();
1501 fVScrollbar->SetPosition(0);
1504 fVScrollbar->SetRange((Int_t)TMath::Ceil((Double_t)container->GetHeight()/(Double_t)fItemVsize),
1505 fVport->GetHeight()/fItemVsize);
1507 ((TGContainer *)container)->ClearViewPort();
1513 void TGListBox::SortByName(Bool_t ascend)
1515 fLbc->GetList()->Sort(ascend);
1517 fLbc->ClearViewPort();
1523 Int_t TGListBox::GetSelected()
const
1525 TGLBContainer *ct = (TGLBContainer *) fVport->GetContainer();
1526 return ct->GetSelected();
1533 void TGListBox::GetSelectedEntries(TList *selected)
1535 fLbc->GetSelectedEntries(selected);
1541 void TGListBox::ChangeBackground(Pixel_t back)
1545 TIter next(fLbc->GetList());
1548 while ((el = (TGFrameElement *)next())) {
1549 TGLBEntry *lbe = (TGLBEntry *)el->fFrame;
1550 lbe->SetBackgroundColor(back);
1552 fLbc->ClearViewPort();
1559 Bool_t TGListBox::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
1561 switch (GET_MSG(msg)) {
1563 switch (GET_SUBMSG(msg)) {
1564 case kSB_SLIDERTRACK:
1566 fVport->SetVPos(Int_t(-parm1 * fItemVsize));
1572 switch (GET_SUBMSG(msg)) {
1575 SendMessage(fMsgWindow, MK_MSG(kC_COMMAND, kCM_LISTBOX),
1577 if (GetMultipleSelections()) SelectionChanged();
1578 TGLBEntry *entry = GetSelectedEntry();
1580 if (entry->InheritsFrom(TGTextLBEntry::Class())) {
1582 text = ((TGTextLBEntry*)entry)->GetText()->GetString();
1585 Selected(fWidgetId, (Int_t) parm1);
1586 Selected((Int_t) parm1);
1590 case kCT_ITEMDBLCLICK:
1591 if (!GetMultipleSelections()) {
1592 TGLBEntry *entry = GetSelectedEntry();
1594 if (entry->InheritsFrom(TGTextLBEntry::Class())) {
1596 text = ((TGTextLBEntry*)entry)->GetText()->GetString();
1597 DoubleClicked(text);
1599 DoubleClicked(fWidgetId, (Int_t) parm1);
1600 DoubleClicked((Int_t) parm1);
1617 void TGListBox::Selected(Int_t widgetId, Int_t
id)
1624 Emit(
"Selected(Int_t,Int_t)", args);
1630 void TGListBox::DoubleClicked(Int_t widgetId, Int_t
id)
1637 Emit(
"DoubleClicked(Int_t,Int_t)", args);
1643 TGLBEntry *TGListBox::FindEntry(
const char *name)
const
1645 TList *list = fLbc->GetList();
1646 TGFrameElement *el = (TGFrameElement *)list->First();
1648 if (el->fFrame->GetTitle() == TString(name))
1649 return (TGLBEntry *)el->fFrame;
1650 el = (TGFrameElement *)list->After(el);
1658 void TGListBox::SavePrimitive(std::ostream &out, Option_t *option )
1660 if (fBackground != GetWhitePixel()) SaveUserColor(out, option);
1662 out << std::endl <<
" // list box" << std::endl;
1664 out<<
" TGListBox *";
1665 out << GetName() <<
" = new TGListBox(" << fParent->GetName();
1667 if (fBackground == GetWhitePixel()) {
1668 if (GetOptions() == (kSunkenFrame | kDoubleBorder)) {
1669 if (fWidgetId == -1) {
1670 out <<
");" << std::endl;
1672 out <<
"," << fWidgetId <<
");" << std::endl;
1675 out <<
"," << fWidgetId <<
"," << GetOptionString() <<
");" << std::endl;
1678 out <<
"," << fWidgetId <<
"," << GetOptionString() <<
",ucolor);" << std::endl;
1680 if (option && strstr(option,
"keep_names"))
1681 out <<
" " << GetName() <<
"->SetName(\"" << GetName() <<
"\");" << std::endl;
1683 if (!fLbc->GetList())
return;
1686 TIter next(fLbc->GetList());
1688 while ((el = (TGFrameElement *) next())) {
1689 out <<
" " << GetName() <<
"->AddEntry(";
1690 el->fFrame->SavePrimitive(out, option);
1691 out <<
");"<< std::endl;
1693 out <<
" " << GetName() <<
"->Resize(" << GetWidth() <<
"," << GetHeight()
1694 <<
");" << std::endl;
1700 void TGTextLBEntry::SavePrimitive(std::ostream &out, Option_t * )
1702 TString content = GetText()->GetString();
1703 content.ReplaceAll(
'\\',
"\\\\");
1704 content.ReplaceAll(
"\"",
"\\\"");
1706 out << quote << content << quote <<
"," << EntryId();