46 ClassImp(TGDockButton);
47 ClassImp(TGDockHideButton);
48 ClassImp(TGUndockedFrame);
49 ClassImp(TGDockableFrame);
54 TGDockButton::TGDockButton(
const TGCompositeFrame *p,
int id) :
55 TGButton (p, id, GetDefaultGC()(), kChildFrame)
57 fWidgetFlags = kWidgetIsEnabled;
59 Resize(10, GetDefaultHeight());
61 fNormBg = fBackground;
63 Float_t r, g, b, h, l, s;
64 TColor::Pixel2RGB(fNormBg, r, g, b);
65 TColor::RGB2HLS(r, g, b, h, l, s);
66 l = l + (1. - l) * 45. / 100.;
67 TColor::HLS2RGB(h, l, s, r, g, b);
68 fHiBg = TColor::RGB2Pixel(r, g, b);
70 AddInput(kEnterWindowMask | kLeaveWindowMask);
77 TGDockButton::~TGDockButton()
84 Bool_t TGDockButton::HandleCrossing(Event_t *event)
86 TGButton::HandleCrossing(event);
87 if (event->fType == kLeaveNotify) {
89 }
else if (event->fType == kEnterNotify) {
93 fClient->NeedRedraw(
this);
101 void TGDockButton::DrawBorder()
103 int options = GetOptions();
105 if (fState == kButtonDown || fState == kButtonEngaged)
107 else if (fMouseOn == kTRUE && IsEnabled()) {
108 SetBackgroundColor(fHiBg);
109 ChangeOptions(kChildFrame);
111 SetBackgroundColor(fNormBg);
112 ChangeOptions(kChildFrame);
114 gVirtualX->ClearWindow(fId);
115 TGFrame::DrawBorder();
117 ChangeOptions(options);
123 void TGDockButton::DoRedraw()
128 if (fState == kButtonDown || fState == kButtonEngaged) { ++x; ++y; }
130 for (
int i = 0; i < 5; i +=4) {
131 gVirtualX->DrawLine(fId, GetHilightGC()(), i+x, y+1, i+x, fHeight-y-3);
132 gVirtualX->DrawLine(fId, GetShadowGC()(), i+x+1, y+1, i+x+1, fHeight-y-3);
140 TGDockHideButton::TGDockHideButton(
const TGCompositeFrame *p) :
151 void TGDockHideButton::DoRedraw()
156 if (fState == kButtonDown || fState == kButtonEngaged) { ++x; ++y; }
159 gVirtualX->DrawLine(fId, GetBlackGC()(), x+1, y+1, x+5, y+3);
160 gVirtualX->DrawLine(fId, GetBlackGC()(), x+1, y+5, x+5, y+3);
161 gVirtualX->DrawLine(fId, GetHilightGC()(), x, y+1, x, y+5);
163 gVirtualX->DrawLine(fId, GetHilightGC()(), x+5, y+1, x+1, y+3);
164 gVirtualX->DrawLine(fId, GetHilightGC()(), x+5, y+5, x+1, y+3);
165 gVirtualX->DrawLine(fId, GetBlackGC()(), x+6, y+1, x+6, y+5);
173 TGUndockedFrame::TGUndockedFrame(
const TGWindow *p, TGDockableFrame *dockable) :
174 TGTransientFrame(p, dockable ? dockable->GetMainFrame() : 0, 10, 10)
177 fDockable = dockable;
179 SetMWMHints(kMWMDecorAll | kMWMDecorResizeH | kMWMDecorMaximize |
180 kMWMDecorMinimize | kMWMDecorMenu,
181 kMWMFuncAll | kMWMFuncResize | kMWMFuncMaximize |
190 TGUndockedFrame::~TGUndockedFrame()
192 if (fDockable && !fDockable->fDeleted) {
193 fDockable->DockContainer(kFALSE);
200 void TGUndockedFrame::FixSize()
202 ChangeOptions(GetOptions() | kFixedSize);
203 SetWMSize(fWidth, fHeight);
204 SetWMSizeHints(fWidth, fHeight, fWidth, fHeight, 0, 0);
210 void TGUndockedFrame::CloseWindow()
219 TGDockableFrame::TGDockableFrame(
const TGWindow *p,
int id, UInt_t )
220 : TGCompositeFrame(p, 10, 10, kHorizontalFrame), TGWidget(id)
222 fMsgWindow = fParent;
224 TGLayoutHints *l1 =
new TGLayoutHints(kLHintsTop | kLHintsLeft);
225 TGLayoutHints *l2 =
new TGLayoutHints(kLHintsExpandY | kLHintsLeft);
226 fLb =
new TGLayoutHints(kLHintsExpandY | kLHintsLeft, 0, 2, 0, 0);
227 fLc =
new TGLayoutHints(kLHintsExpandY | kLHintsExpandX);
229 fButtons =
new TGCompositeFrame(
this, 10, 10, kVerticalFrame);
230 fButtons->SetCleanup();
231 fHideButton =
new TGDockHideButton(fButtons);
232 fButtons->AddFrame(fHideButton, l1);
233 fDockButton =
new TGDockButton(fButtons);
234 fButtons->AddFrame(fDockButton, l2);
236 TGCompositeFrame::AddFrame(fButtons, fLb);
238 fContainer =
new TGCompositeFrame(
this, 10, 10);
240 TGCompositeFrame::AddFrame(fContainer, fLc);
243 fEnableUndock = kTRUE;
249 fDockButton->Associate(
this);
250 fHideButton->Associate(
this);
253 Resize(GetDefaultSize());
254 TGFrame::SetWindowName();
260 TGDockableFrame::~TGDockableFrame()
273 void TGDockableFrame::AddFrame(TGFrame *f, TGLayoutHints *hints)
275 f->ReparentWindow(fContainer);
276 fContainer->AddFrame(f, fHints = hints);
277 fContainer->Layout();
283 void TGDockableFrame::UndockContainer()
288 if (fFrame || !fEnableUndock)
return;
290 fFrame =
new TGUndockedFrame(fClient->GetDefaultRoot(),
this);
291 fFrame->SetEditDisabled();
293 TGDimension size = fContainer->GetSize();
294 RemoveFrame(fContainer);
295 fContainer->ReparentWindow(fFrame);
296 fFrame->AddFrame(fContainer,
new TGLayoutHints(kLHintsExpandY | kLHintsExpandX));
298 gVirtualX->TranslateCoordinates(GetId(), fClient->GetDefaultRoot()->GetId(), fX,
299 fY + fFrame->GetHeight(), ax, ay, wdummy);
301 if (fDockName) fFrame->SetWindowName(fDockName);
303 fFrame->MapSubwindows();
304 fFrame->Resize(size);
308 fFrame->Move(ax, ay);
310 if (((TGFrame *)fParent)->IsComposite())
311 ((TGCompositeFrame *)fParent)->HideFrame(
this);
315 SendMessage(fMsgWindow, MK_MSG(kC_DOCK, kDOCK_UNDOCK), fWidgetId, 0);
322 void TGDockableFrame::DockContainer(Int_t del)
330 fFrame->RemoveFrame(fContainer);
331 fContainer->ReparentWindow(
this);
332 TGCompositeFrame::AddFrame(fContainer,
new TGLayoutHints(kLHintsExpandY | kLHintsExpandX));
335 fDockButton->Resize(fDockButton->GetDefaultWidth(), 1);
338 if (((TGFrame *)fParent)->IsComposite())
339 ((TGCompositeFrame *)fParent)->ShowFrame(
this);
347 SendMessage(fMsgWindow, MK_MSG(kC_DOCK, kDOCK_DOCK), fWidgetId, 0);
354 void TGDockableFrame::ShowContainer()
356 if (!fHidden)
return;
358 ShowFrame(fContainer);
359 if (fEnableUndock) fButtons->ShowFrame(fDockButton);
360 fHideButton->SetAspectRatio(0);
361 if (((TGFrame *)fParent)->IsComposite())
362 ((TGCompositeFrame *)fParent)->Layout();
365 SendMessage(fMsgWindow, MK_MSG(kC_DOCK, kDOCK_SHOW), fWidgetId, 0);
371 void TGDockableFrame::HideContainer()
373 if (fHidden || !fEnableHide)
return;
375 HideFrame(fContainer);
376 fButtons->HideFrame(fDockButton);
377 fHideButton->SetAspectRatio(1);
378 if (((TGFrame *)fParent)->IsComposite())
379 ((TGCompositeFrame *)fParent)->Layout();
382 SendMessage(fMsgWindow, MK_MSG(kC_DOCK, kDOCK_HIDE),fWidgetId, 0);
388 Bool_t TGDockableFrame::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
390 switch (GET_MSG(msg)) {
392 switch (GET_SUBMSG(msg)) {
396 if (!fHidden) UndockContainer();
416 void TGDockableFrame::EnableUndock(Bool_t onoff)
418 fEnableUndock = onoff;
420 fButtons->ShowFrame(fDockButton);
422 fButtons->HideFrame(fDockButton);
429 void TGDockableFrame::EnableHide(Bool_t onoff)
433 fButtons->ShowFrame(fHideButton);
435 fButtons->HideFrame(fHideButton);
442 void TGDockableFrame::SetWindowName(
const char *name)
447 if (fFrame) fFrame->SetWindowName(fDockName);
454 void TGDockableFrame::SavePrimitive(std::ostream &out, Option_t *option )
458 out << std::endl <<
" // dockable frame" << std::endl;
459 out <<
" TGDockableFrame *";
460 out << GetName()<<
" = new TGDockableFrame(" << fParent->GetName();
462 if (GetOptions() == kHorizontalFrame) {
463 if (fWidgetId == -1) {
464 out <<
");" << std::endl;
466 out <<
"," << fWidgetId <<
");" << std::endl;
469 out <<
"," << fWidgetId <<
"," << GetOptionString() <<
");" << std::endl;
471 if (option && strstr(option,
"keep_names"))
472 out <<
" " << GetName() <<
"->SetName(\"" << GetName() <<
"\");" << std::endl;
474 if (GetContainer()->GetList()->First()) {
475 out <<
" TGCompositeFrame *" << GetContainer()->GetName() <<
" = "
476 << GetName() <<
"->GetContainer();" << std::endl;
479 TIter next(GetContainer()->GetList());
481 while ((el = (TGFrameElement *) next())) {
482 el->fFrame->SavePrimitive(out, option);
483 out <<
" " << GetName() <<
"->AddFrame(" << el->fFrame->GetName();
484 el->fLayout->SavePrimitive(out, option);
485 out <<
");"<< std::endl;
488 out << std::endl <<
" // next lines belong to the dockable frame widget" << std::endl;
490 out <<
" " << GetName() <<
"->EnableUndock(kTRUE);" << std::endl;
492 out <<
" " << GetName() <<
"->EnableUndock(kFALSE);" << std::endl;
495 out <<
" " << GetName() <<
"->EnableHide(kTRUE);" << std::endl;
497 out <<
" " << GetName() <<
"->EnableHide(kFALSE);" << std::endl;
500 out <<
" " << GetName() <<
"->SetWindowName(" << quote << fDockName
501 << quote <<
");" << std::endl;
504 out <<
" " << GetName() <<
"->UndockContainer();" << std::endl;
506 out <<
" " << GetName() <<
"->DockContainer();" << std::endl;
509 out <<
" " << GetName() <<
"->HideContainer();" << std::endl;