30 ClassImp(TGShutterItem);
36 TGShutter::TGShutter(
const TGWindow *p, UInt_t options) :
37 TGCompositeFrame(p, 10, 10, options)
43 fClosingHadScrollbar = kFALSE;
47 fDefWidth = fDefHeight = 0;
50 delete fLayoutManager;
57 TGShutter::~TGShutter()
59 if (fTimer)
delete fTimer;
71 void TGShutter::AddItem(TGShutterItem *item)
73 TGLayoutHints *hints =
new TGLayoutHints(kLHintsExpandX | kLHintsExpandY);
74 AddFrame(item, hints);
84 void TGShutter::RemoveItem(
const char *name)
86 TGShutterItem *item = GetItem(name);
92 if (fList->GetEntries() <= 1) {
96 if (item == fSelectedItem) {
97 TGFrameElement *fe = (TGFrameElement*)fList->FindObject(item->GetFrameElement());
99 TGFrameElement *sel = (TGFrameElement*)fList->Before(fe);
101 sel = (TGFrameElement*)fList->After(fe);
106 SetSelectedItem((TGShutterItem*)sel->fFrame);
111 item->DestroyWindow();
119 void TGShutter::RemovePage()
121 if (!fSelectedItem) {
124 TGTextButton *btn = (TGTextButton*)fSelectedItem->GetButton();
125 RemoveItem(btn->GetString().Data());
131 void TGShutter::RenamePage(
const char *name)
133 if (!fSelectedItem) {
136 TGTextButton *btn = (TGTextButton*)fSelectedItem->GetButton();
143 TGShutterItem *TGShutter::AddPage(
const char *name)
145 static int id = 1000;
146 TGShutterItem *item =
new TGShutterItem(
this,
new TGHotString(name),
id++);
156 Bool_t TGShutter::ProcessMessage(Long_t , Long_t parm1, Long_t )
158 if (!fList)
return kFALSE;
161 TGShutterItem *child, *item = 0;
164 while ((el = (TGFrameElement *) next())) {
165 child = (TGShutterItem *) el->fFrame;
166 if (parm1 == child->WidgetId()) {
172 if (!item)
return kFALSE;
175 fSelectedItem = (TGShutterItem*) ((TGFrameElement*)fList->First())->fFrame;
176 if (fSelectedItem == item)
return kTRUE;
178 fHeightIncrement = 1;
179 fClosingItem = fSelectedItem;
180 fClosingHeight = fClosingItem->GetHeight();
181 fClosingHeight -= fClosingItem->fButton->GetDefaultHeight();
182 fSelectedItem = item;
183 Selected(fSelectedItem);
184 fSelectedItem->Selected();
186 if (!fTimer) fTimer =
new TTimer(
this, 6);
196 Bool_t TGShutter::HandleTimer(TTimer *)
198 if (!fClosingItem)
return kFALSE;
199 fClosingHeight -= fHeightIncrement;
200 fHeightIncrement += 5;
201 if (fClosingHeight > 0) {
216 void TGShutter::Layout()
219 TGShutterItem *child;
225 fSelectedItem = (TGShutterItem*) ((TGFrameElement*)GetList()->First())->fFrame;
227 exh = Int_t(fHeight - (fBorderWidth << 1));
229 while ((el = (TGFrameElement *) next())) {
230 child = (TGShutterItem *) el->fFrame;
231 bh = child->fButton->GetDefaultHeight();
237 while ((el = (TGFrameElement *) next())) {
238 child = (TGShutterItem *) el->fFrame;
239 bh = child->fButton->GetDefaultHeight();
240 if (child == fSelectedItem) {
242 child->fCanvas->SetScrolling(TGCanvas::kCanvasNoScroll);
244 child->fCanvas->SetScrolling(TGCanvas::kCanvasScrollVertical);
245 child->ShowFrame(child->fCanvas);
246 child->MoveResize(fBorderWidth, y, fWidth - (fBorderWidth << 1),
247 exh - fClosingHeight + bh);
248 y += exh - fClosingHeight + bh;
249 }
else if (child == fClosingItem) {
250 child->fCanvas->SetScrolling(TGCanvas::kCanvasNoScroll);
251 child->MoveResize(fBorderWidth, y, fWidth - (fBorderWidth << 1),
252 fClosingHeight + bh);
253 y += fClosingHeight + bh;
255 child->MoveResize(fBorderWidth, y, fWidth - (fBorderWidth << 1), bh);
256 child->HideFrame(child->fCanvas);
265 void TGShutter::SetSelectedItem(TGShutterItem *item)
267 fSelectedItem = item;
268 fSelectedItem->Selected();
275 void TGShutter::SetSelectedItem(
const char *name)
277 TGShutterItem *item = GetItem(name);
281 SetSelectedItem(item);
287 void TGShutter::EnableItem(
const char *name, Bool_t on)
289 TGShutterItem *item = GetItem(name);
294 item->GetButton()->SetEnabled(on);
300 TGShutterItem *TGShutter::GetItem(
const char *name)
303 TGShutterItem *item = 0;
307 while ((el = (TGFrameElement *) next())) {
309 item = (TGShutterItem *)el->fFrame;
310 btn = (TGTextButton*)item->GetButton();
311 if (btn->GetString() == name)
return item;
320 TGDimension TGShutter::GetDefaultSize()
const
322 UInt_t w = (GetOptions() & kFixedWidth) || (fDefWidth == 0) ? fWidth : fDefWidth;
323 UInt_t h = (GetOptions() & kFixedHeight) || (fDefHeight == 0) ? fHeight : fDefHeight;
324 return TGDimension(w, h);
330 void TGShutter::SetDefaultSize(UInt_t w, UInt_t h)
340 TGShutterItem::TGShutterItem(
const TGWindow *p, TGHotString *s, Int_t
id,
342 TGVerticalFrame (p, 10, 10, options), TGWidget (id)
349 fButton =
new TGTextButton(
this, s,
id);
350 fCanvas =
new TGCanvas(
this, 10, 10, kChildFrame);
351 fContainer =
new TGVerticalFrame(fCanvas->GetViewPort(), 10, 10, kOwnBackground);
352 fCanvas->SetContainer(fContainer);
353 fContainer->SetBackgroundColor(fClient->GetShadow(GetDefaultFrameBackground()));
355 AddFrame(fButton, fL1 =
new TGLayoutHints(kLHintsTop | kLHintsExpandX));
356 AddFrame(fCanvas, fL2 =
new TGLayoutHints(kLHintsExpandY | kLHintsExpandX));
358 fButton->Associate((TGFrame *) p);
360 fCanvas->SetEditDisabled(kEditDisableGrab | kEditDisableLayout);
361 fButton->SetEditDisabled(kEditDisableGrab | kEditDisableBtnEnable);
362 fContainer->SetEditDisabled(kEditDisableGrab);
363 fEditDisabled = kEditDisableGrab | kEditDisableLayout;
369 TGShutterItem::~TGShutterItem()
371 if (!IsZombie() && !MustCleanup()) {
383 void TGShutterItem::SavePrimitive(std::ostream &out, Option_t *option )
386 TGTextButton *b = (TGTextButton *)fButton;
387 const char *text = b->GetText()->GetString();
388 char hotpos = b->GetText()->GetHotPos();
389 Int_t lentext = b->GetText()->GetLength();
390 char *outext =
new char[lentext+2];
406 out <<
" // " << quote << outext << quote <<
" shutter item " << std::endl;
407 out <<
" TGShutterItem *";
408 out << GetName() <<
" = new TGShutterItem(" << fParent->GetName()
409 <<
", new TGHotString(" << quote << outext << quote <<
"),"
410 << fButton->WidgetId() <<
"," << GetOptionString() <<
");" << std::endl;
413 if (option && strstr(option,
"keep_names"))
414 out <<
" " << GetName() <<
"->SetName(\"" << GetName() <<
"\");" << std::endl;
416 TList *list = ((TGCompositeFrame *)GetContainer())->GetList();
420 out <<
" TGCompositeFrame *" << GetContainer()->GetName()
421 <<
" = (TGCompositeFrame *)" << GetName() <<
"->GetContainer();" << std::endl;
426 while ((el = (TGFrameElement *) next())) {
427 el->fFrame->SavePrimitive(out, option);
428 out <<
" " << GetContainer()->GetName() <<
"->AddFrame(" << el->fFrame->GetName();
429 el->fLayout->SavePrimitive(out, option);
430 out <<
");"<< std::endl;
437 void TGShutter::SavePrimitive(std::ostream &out, Option_t *option )
440 out <<
" // shutter" << std::endl;
442 out <<
" TGShutter *";
443 out << GetName() <<
" = new TGShutter(" << fParent->GetName() <<
","
444 << GetOptionString() <<
");" << std::endl;
446 if ((fDefWidth > 0) || (fDefHeight > 0)) {
447 out <<
" " << GetName() <<
"->SetDefaultSize(";
448 out << fDefWidth <<
"," << fDefHeight <<
");" << std::endl;
450 if (option && strstr(option,
"keep_names"))
451 out <<
" " << GetName() <<
"->SetName(\"" << GetName() <<
"\");" << std::endl;
458 while ((el = (TGFrameElement *) next())) {
459 el->fFrame->SavePrimitive(out, option);
460 out <<
" " << GetName() <<
"->AddItem(" << el->fFrame->GetName();
462 out <<
");"<< std::endl;
465 out <<
" " << GetName() <<
"->SetSelectedItem("
466 << GetSelectedItem()->GetName() <<
");" << std::endl;
467 out <<
" " <<GetName()<<
"->Resize("<<GetWidth()<<
","<<GetHeight()<<
");"<<std::endl;