forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TEveWindow.cxx
1503 lines (1159 loc) · 43.4 KB
/
TEveWindow.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// @(#)root/eve:$Id$
// Author: Matevz Tadel 2007
/*************************************************************************
* Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#include "TEveWindow.h"
#include "TEveWindowManager.h"
#include "TEveManager.h"
#include "TEveSelection.h"
#include "THashList.h"
#include "TGButton.h"
#include "TGPack.h"
#include "TGTab.h"
#include "TRootContextMenu.h"
#include "TVirtualX.h"
#include <cassert>
/** \class TEveCompositeFrame
\ingroup TEve
Abstract base-class for frame-slots that encompass EVE-windows
(sub-classes of TEveWindow).
The EVE-frame classes are managed by their embedded EVE-windows and
mostly serve as an interface to particular ROOT widgets
(sub-classes of TGCompositeFrame) they are embedded into.
This base-class, a sub-class of a vertical composite-frame, creates
also the title-bar which can be used to interact with the embedded
window. Optionally, the title-bar can be replaced with a mini-bar
(a 4-pixel thin bar at the top). By clicking on the mini-bar, the
title-bar is restored.
Sub-classes provide for specific behaviour and expectations of
individual ROOT GUI container frames.
POSSIBLE EXTENSIONS
No frame is drawn around this composite-frame - frame style could be
available as a (static) member.
Menus of embedded windows could also be managed - hidden or transposed
to a top-level menubar.
*/
ClassImp(TEveCompositeFrame);
TEveContextMenu* TEveCompositeFrame::fgCtxMenu = nullptr;
const TString TEveCompositeFrame::fgkEmptyFrameName("<relinquished>");
TList* TEveCompositeFrame::fgFrameList = new THashList;
TEveCompositeFrame::IconBarCreator_foo TEveCompositeFrame::fgIconBarCreator = nullptr;
UInt_t TEveCompositeFrame::fgTopFrameHeight = 14;
UInt_t TEveCompositeFrame::fgMiniBarHeight = 4;
Bool_t TEveCompositeFrame::fgAllowTopFrameCollapse = kTRUE;
////////////////////////////////////////////////////////////////////////////////
/// Set properties of the EVE frame.
/// Should be called before the windows are created.
void TEveCompositeFrame::SetupFrameMarkup(IconBarCreator_foo creator,
UInt_t top_frame_height,
UInt_t mini_bar_height,
Bool_t allow_top_collapse)
{
fgIconBarCreator = creator;
fgTopFrameHeight = top_frame_height;
fgMiniBarHeight = mini_bar_height;
fgAllowTopFrameCollapse = allow_top_collapse;
}
////////////////////////////////////////////////////////////////////////////////
/// Constructor.
TEveCompositeFrame::TEveCompositeFrame(TGCompositeFrame* parent,
TEveWindow* eve_parent) :
TGCompositeFrame (parent, 0, 0, kVerticalFrame),
fTopFrame (nullptr),
fToggleBar (nullptr),
fTitleBar (nullptr),
fIconBar (nullptr),
fEveWindowLH (nullptr),
fMiniBar (nullptr),
fEveParent (eve_parent),
fEveWindow (nullptr),
fShowInSync (kTRUE)
{
fTopFrame = new TGHorizontalFrame(this, 20, fgTopFrameHeight);
if (fgAllowTopFrameCollapse)
{
fToggleBar = new TGTextButton(fTopFrame, "Hide");
fToggleBar->ChangeOptions(kRaisedFrame);
fToggleBar->Resize(40, fgTopFrameHeight);
fToggleBar->Connect("Clicked()", "TEveCompositeFrame", this, "FlipTitleBarState()");
fTopFrame->AddFrame(fToggleBar, new TGLayoutHints(kLHintsNormal));
}
fTitleBar = new TGTextButton(fTopFrame, "Title Bar");
fTitleBar->ChangeOptions(kRaisedFrame);
fTitleBar->Resize(40, fgTopFrameHeight);
fTitleBar->Connect("Clicked()", "TEveCompositeFrame", this, "TitleBarClicked()");
fTopFrame->AddFrame(fTitleBar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
if (fgIconBarCreator)
{
fIconBar = (fgIconBarCreator)(this, fTopFrame, fgTopFrameHeight);
}
else
{
TGButton* b = new TGTextButton(fTopFrame, "Actions");
b->ChangeOptions(kRaisedFrame);
b->Resize(40, fgTopFrameHeight);
b->Connect("Pressed()", "TEveCompositeFrame", this, "ActionPressed()");
fIconBar = b;
}
fTopFrame->AddFrame(fIconBar, new TGLayoutHints(kLHintsNormal));
AddFrame(fTopFrame, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
// --- MiniBar
if (fgAllowTopFrameCollapse)
{
fMiniBar = new TGButton(this);
fMiniBar->ChangeOptions(kRaisedFrame | kFixedHeight);
fMiniBar->Resize(20, fgMiniBarHeight);
fMiniBar->SetBackgroundColor(TEveWindow::GetMiniBarBackgroundColor());
fMiniBar->Connect("Clicked()", "TEveCompositeFrame", this, "FlipTitleBarState()");
AddFrame(fMiniBar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
}
// --- Common settings.
fTopFrame->SetCleanup(kLocalCleanup);
SetCleanup(kLocalCleanup);
MapSubwindows();
HideFrame(fMiniBar);
SetMapSubwindows(kFALSE);
// Layout for embedded windows.
fEveWindowLH = new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY);
// !!! The following should actually be done somewhere else, in
// some not-yet-existing static method of TEveWindow. Right now the
// eve-frame-creation code is still a little bit everywhere.
if (fEveParent == nullptr)
fEveParent = gEve->GetWindowManager();
fgFrameList->Add(this);
}
////////////////////////////////////////////////////////////////////////////////
/// If fEveWindow != 0 we are being deleted from the ROOT GUI side.
/// Relinquish EveWindow and ref-counting should do the rest.
TEveCompositeFrame::~TEveCompositeFrame()
{
fgFrameList->Remove(this);
if (fEveWindow != nullptr)
{
if (gDebug > 0)
Info("TEveCompositeFrame::~TEveCompositeFrame",
"EveWindow not null '%s', relinquishing it now.",
fEveWindow->GetElementName());
fEveWindow->ClearEveFrame();
RelinquishEveWindow();
}
delete fEveWindowLH;
}
////////////////////////////////////////////////////////////////////////////////
/// Update widgets using window's name or title.
void TEveCompositeFrame::WindowNameChanged(const TString& name)
{
fTitleBar->SetText(name);
}
////////////////////////////////////////////////////////////////////////////////
/// Accept window and increase its deny-destroy count.
/// Window's gui-frame is embedded and mapped.
/// Layout is not called.
///
/// Throws an exception if a window is already embedded or if 0 is
/// passed as an argument.
void TEveCompositeFrame::AcquireEveWindow(TEveWindow* ew)
{
// Replace current eve-window with the given one.
// Current GUI window is unmapped, removed and reparented to default-root.
// New GUI window is reparented to this, added and mapped.
static const TEveException eh("TEveCompositeFrame::AcquireEveWindow ");
if (fEveWindow)
throw eh + "Window already set.";
if (ew == nullptr)
throw eh + "Called with 0 argument.";
fEveWindow = ew;
fEveWindow->IncDenyDestroy();
TGFrame* gui_frame = fEveWindow->GetGUIFrame();
gui_frame->ReparentWindow(this);
AddFrame(gui_frame, fEveWindowLH);
fEveWindow->PostDock();
gui_frame->MapWindow();
SetCurrent(fEveWindow->IsCurrent());
SetShowTitleBar(fEveWindow->GetShowTitleBar());
WindowNameChanged(fEveWindow->GetElementName());
}
////////////////////////////////////////////////////////////////////////////////
/// Remove window and decrease its deny-destroy count.
/// Window's gui-frame is unmapped, removed and, if reparent flag is
/// true (default), reparented to default-root.
TEveWindow* TEveCompositeFrame::RelinquishEveWindow(Bool_t reparent)
{
TEveWindow* ex_ew = fEveWindow;
if (fEveWindow)
{
TGFrame* gui_frame = fEveWindow->GetGUIFrame();
gui_frame->UnmapWindow();
fEveWindow->PreUndock();
RemoveFrame(gui_frame);
if (reparent)
gui_frame->ReparentWindow(fClient->GetDefaultRoot());
fEveWindow->DecDenyDestroy();
fEveWindow = nullptr;
SetCurrent(kFALSE);
WindowNameChanged(fgkEmptyFrameName);
}
return ex_ew;
}
////////////////////////////////////////////////////////////////////////////////
/// Returns eve-parent dynamic-casted to TEveWindow.
TEveWindow* TEveCompositeFrame::GetEveParentAsWindow() const
{
return dynamic_cast<TEveWindow*>(fEveParent);
}
////////////////////////////////////////////////////////////////////////////////
/// Set current state of this frame.
/// This is called by the management functions in TEveWindow.
void TEveCompositeFrame::SetCurrent(Bool_t curr)
{
if (curr) {
fTitleBar->SetBackgroundColor(TEveWindow::GetCurrentBackgroundColor());
} else {
fTitleBar->SetBackgroundColor(GetDefaultFrameBackground());
}
fClient->NeedRedraw(fTitleBar);
}
////////////////////////////////////////////////////////////////////////////////
/// Set state of title-bar. This toggles between the display of the full
/// title-bar and 4-pixel-high mini-bar.
void TEveCompositeFrame::SetShowTitleBar(Bool_t show)
{
if (show) {
HideFrame(fMiniBar);
ShowFrame(fTopFrame);
} else {
HideFrame(fTopFrame);
ShowFrame(fMiniBar);
}
fShowInSync = show == fEveWindow->GetShowTitleBar();
}
////////////////////////////////////////////////////////////////////////////////
/// Hide title-bar and mini-bar.
void TEveCompositeFrame::HideAllDecorations()
{
HideFrame(fTopFrame);
HideFrame(fMiniBar);
fShowInSync = kFALSE;
}
////////////////////////////////////////////////////////////////////////////////
/// Show title-bar or mini-bar, as dictated by the window.
void TEveCompositeFrame::ShowNormalDecorations()
{
SetShowTitleBar(fEveWindow->GetShowTitleBar());
}
////////////////////////////////////////////////////////////////////////////////
/// The action-button of the title-bar was pressed.
/// This opens context menu of the eve-window.
void TEveCompositeFrame::ActionPressed()
{
if (fgCtxMenu == nullptr) {
fgCtxMenu = new TEveContextMenu("", "");
}
fgCtxMenu->SetupAndPopup(fIconBar, fEveWindow);
}
////////////////////////////////////////////////////////////////////////////////
/// Change display-state of the title-bar / mini-bar.
/// This function is used as a slot and passes the call to eve-window.
void TEveCompositeFrame::FlipTitleBarState()
{
if (fShowInSync)
fEveWindow->FlipShowTitleBar();
else
SetShowTitleBar(fEveWindow->GetShowTitleBar());
}
////////////////////////////////////////////////////////////////////////////////
/// Slot for mouse-click on the central part of the title-bar.
/// The call is passed to eve-window.
void TEveCompositeFrame::TitleBarClicked()
{
fEveWindow->TitleBarClicked();
}
/** \class TEveCompositeFrameInMainFrame
\ingroup TEve
An EVE window-slot contained within a TGMainFrame.
*/
ClassImp(TEveCompositeFrameInMainFrame);
////////////////////////////////////////////////////////////////////////////////
/// Constructor.
TEveCompositeFrameInMainFrame::TEveCompositeFrameInMainFrame(TGCompositeFrame* parent,
TEveWindow* eve_parent,
TGMainFrame* mf) :
TEveCompositeFrame(parent, eve_parent),
fMainFrame (mf),
fOriginalSlot (nullptr),
fOriginalContainer (nullptr)
{
fMainFrame->Connect("CloseWindow()", "TEveCompositeFrameInMainFrame", this, "MainFrameClosed()");
gEve->GetWindowManager()->Connect("WindowDeleted(TEveWindow*)", "TEveCompositeFrameInMainFrame", this, "SomeWindowClosed(TEveWindow*)");
}
////////////////////////////////////////////////////////////////////////////////
/// Destructor.
TEveCompositeFrameInMainFrame::~TEveCompositeFrameInMainFrame()
{
if (gDebug > 0)
Info("~TEveCompositeFrameInMainFrame", "Destructor.");
// MainFrames get deleted with a time-out. So, during EVE manager
// shutdown, it might happen that this gets called when gEve is null.
if (gEve && gEve->GetWindowManager())
{
gEve->GetWindowManager()->Disconnect("WindowDeleted(TEveWindow*)", this, "SomeWindowClosed(TEveWindow*)");
}
else
{
Info("~TEveCompositeFrameInMainFrame", "gEve null - OK if it was terminated.");
}
}
////////////////////////////////////////////////////////////////////////////////
/// Update widgets using window's name or title.
void TEveCompositeFrameInMainFrame::WindowNameChanged(const TString& name)
{
fMainFrame->SetWindowName(name);
TEveCompositeFrame::WindowNameChanged(name);
}
////////////////////////////////////////////////////////////////////////////////
/// Virtual function called from eve side when the frame should be
/// destroyed. This means we expect that fEveWindow is null.
///
/// We simply call CloseWindow() on the main-frame which will in
/// turn generate the "CloseWindow()" signal.
/// This is then handled in MainFrameClosed().
void TEveCompositeFrameInMainFrame::Destroy()
{
if (gDebug > 0)
Info("TEveCompositeFrameInMainFrame::Destroy()",
"Propagating call to main-frame.");
assert (fEveWindow == nullptr);
fMainFrame->CloseWindow();
}
////////////////////////////////////////////////////////////////////////////////
/// Set the container where to return the contained window on destruction.
void TEveCompositeFrameInMainFrame::SetOriginalSlotAndContainer(TEveWindow* slot,
TEveWindow* container)
{
static const TEveException kEH("TEveCompositeFrameInMainFrame::SetOriginalSlotAndContainer ");
if (container && ! container->CanMakeNewSlots())
throw kEH + "Given window can not make new slots.";
fOriginalSlot = slot;
fOriginalContainer = container;
}
////////////////////////////////////////////////////////////////////////////////
/// Slot called when a window is closed ... we check that this was
/// not our original container.
void TEveCompositeFrameInMainFrame::SomeWindowClosed(TEveWindow* w)
{
if (w == fOriginalSlot)
fOriginalSlot = nullptr;
if (w == fOriginalContainer)
fOriginalContainer = nullptr;
}
////////////////////////////////////////////////////////////////////////////////
/// Slot for main-frame's "CloseWindow()" signal.
/// If an eve window is still present, it will be put into:
/// - original-container, if it is set;
//// - into window-managers default-container.
void TEveCompositeFrameInMainFrame::MainFrameClosed()
{
if (fEveWindow != nullptr)
{
TEveWindow* swapCandidate = nullptr;
if (fOriginalSlot)
{
// if use pack, show hidden slot
TEveCompositeFrameInPack* packFrame = dynamic_cast<TEveCompositeFrameInPack*>(fOriginalSlot->GetEveFrame());
if (packFrame) {
TGPack* pack = (TGPack*)(packFrame->GetParent());
pack->ShowFrame(packFrame);
}
swapCandidate = fOriginalSlot;
}
else if (fOriginalContainer)
{
swapCandidate = fOriginalContainer->NewSlot();
}
else if (gEve->GetWindowManager()->HasDefaultContainer())
{
swapCandidate = gEve->GetWindowManager()->GetDefaultContainer()->NewSlot();
}
if (swapCandidate)
{
TEveWindow::SwapWindows(fEveWindow, swapCandidate);
gEve->GetWindowManager()->WindowDocked(fEveWindow );
}
}
fMainFrame->DontCallClose();
if (fEveWindow != nullptr)
fEveWindow->DestroyWindowAndSlot();
if (gDebug > 0)
Info("TEveCompositeFrameInMainFrame::MainFrameClosed()",
"Expecting destructor call soon.");
}
/** \class TEveCompositeFrameInPack
\ingroup TEve
An EVE window-slot contained within one frame of a TGPack.
*/
ClassImp(TEveCompositeFrameInPack);
////////////////////////////////////////////////////////////////////////////////
/// Constructor.
TEveCompositeFrameInPack::TEveCompositeFrameInPack(TGCompositeFrame* parent,
TEveWindow* eve_parent,
TGPack* pack) :
TEveCompositeFrame(parent, eve_parent),
fPack (pack)
{
}
////////////////////////////////////////////////////////////////////////////////
/// Destructor.
TEveCompositeFrameInPack::~TEveCompositeFrameInPack()
{
}
////////////////////////////////////////////////////////////////////////////////
/// Virtual function called from eve side when the frame should be
/// destroyed. This means we expect that fEveWindow is null.
///
/// Remove the frame from pack and delete it.
void TEveCompositeFrameInPack::Destroy()
{
if (gDebug > 0)
Info("TEveCompositeFrameInPack::Destroy()", "Removing from pack and deleting.");
assert(fEveWindow == nullptr);
fPack->RemoveFrame(this);
delete this;
}
/** \class TEveCompositeFrameInTab
\ingroup TEve
An EVE window-slot contained within one tab of a TGTab.
*/
ClassImp(TEveCompositeFrameInTab);
////////////////////////////////////////////////////////////////////////////////
/// Constructor.
TEveCompositeFrameInTab::TEveCompositeFrameInTab(TGCompositeFrame* parent,
TEveWindow* eve_parent,
TGTab* tab) :
TEveCompositeFrame(parent, eve_parent),
fTab (tab),
fParentInTab (parent)
{
}
////////////////////////////////////////////////////////////////////////////////
/// Destructor.
TEveCompositeFrameInTab::~TEveCompositeFrameInTab()
{
}
////////////////////////////////////////////////////////////////////////////////
/// Update widgets using window's name or title.
void TEveCompositeFrameInTab::WindowNameChanged(const TString& name)
{
Int_t t = FindTabIndex();
fTab->GetTabTab(t)->SetText(new TGString(name));
fTab->Layout();
TEveCompositeFrame::WindowNameChanged(name);
}
////////////////////////////////////////////////////////////////////////////////
/// Return index of this frame in the tab.
/// Throws an exception if it is not found.
Int_t TEveCompositeFrameInTab::FindTabIndex()
{
static const TEveException eh("TEveCompositeFrameInTab::FindTabIndex ");
Int_t nt = fTab->GetNumberOfTabs();
for (Int_t t = 0; t < nt; ++t)
{
if (fTab->GetTabContainer(t) == fParentInTab)
{
return t;
}
}
throw eh + "parent frame not found in tab.";
}
////////////////////////////////////////////////////////////////////////////////
/// Virtual function called from eve side when the frame should be
/// destroyed. This means we expect that fEveWindow is null.
///
/// Remove the frame from tab and delete it.
void TEveCompositeFrameInTab::Destroy()
{
if (gDebug > 0)
Info("TEveCompositeFrameInTab::Destroy()", "Removing from tab and deleting.");
assert (fEveWindow == nullptr);
Int_t t = FindTabIndex();
// disconnect form Removed() if / when connected
fTab->RemoveTab(t, kFALSE);
fParentInTab->DestroyWindow();
fParentInTab->SetCleanup(kNoCleanup);
delete fParentInTab;
delete this;
}
////////////////////////////////////////////////////////////////////////////////
/// Set current state of this frame.
/// Virtual from TEveCompositeFrame.
void TEveCompositeFrameInTab::SetCurrent(Bool_t curr)
{
TEveCompositeFrame::SetCurrent(curr);
Int_t t = FindTabIndex();
TGTabElement* te = fTab->GetTabTab(t);
if (curr) {
te->SetBackgroundColor(TEveWindow::GetCurrentBackgroundColor());
} else {
te->SetBackgroundColor(GetDefaultFrameBackground());
}
fClient->NeedRedraw(te);
}
/** \class TEveWindow
\ingroup TEve
Abstract base-class for representing eve-windows.
Sub-classes define a particular GUI frame that gets showin the window.
*/
ClassImp(TEveWindow);
UInt_t TEveWindow::fgMainFrameDefWidth = 640;
UInt_t TEveWindow::fgMainFrameDefHeight = 480;
Pixel_t TEveWindow::fgCurrentBackgroundColor = 0x80A0C0;
Pixel_t TEveWindow::fgMiniBarBackgroundColor = 0x80C0A0;
////////////////////////////////////////////////////////////////////////////////
TEveWindow::TEveWindow(const char* n, const char* t) :
TEveElementList(n, t),
fEveFrame (nullptr),
fShowTitleBar (kTRUE)
{
// Constructor.
// Override from TEveElementList.
fChildClass = TEveWindow::Class();
}
////////////////////////////////////////////////////////////////////////////////
/// Destructor.
TEveWindow::~TEveWindow()
{
if (gDebug > 0)
Info("~TEveWindow", "name='%s', deny-destroy=%d.",
GetElementName(), fDenyDestroy);
}
////////////////////////////////////////////////////////////////////////////////
/// Called before the element is deleted, thus offering the last chance
/// to detach from acquired resources and from the framework itself.
/// Here the request is just passed to TEveManager.
/// If you override it, make sure to call base-class version.
void TEveWindow::PreDeleteElement()
{
gEve->GetWindowManager()->DeleteWindow(this);
TEveElementList::PreDeleteElement();
}
////////////////////////////////////////////////////////////////////////////////
/// Virtual function called before a window is undocked.
void TEveWindow::PreUndock()
{
for (List_ci i=fChildren.begin(); i!=fChildren.end(); ++i)
{
TEveWindow* w = dynamic_cast<TEveWindow*>(*i);
if (w)
w->PreUndock();
}
}
////////////////////////////////////////////////////////////////////////////////
/// Virtual function called after a window is docked.
void TEveWindow::PostDock()
{
for (List_ci i=fChildren.begin(); i!=fChildren.end(); ++i)
{
TEveWindow* w = dynamic_cast<TEveWindow*>(*i);
if (w)
w->PostDock();
}
}
////////////////////////////////////////////////////////////////////////////////
/// Name or title of the window changed - propagate to frames.
/// Virtual from TEveElement.
void TEveWindow::NameTitleChanged()
{
fEveFrame->WindowNameChanged(GetElementName());
}
////////////////////////////////////////////////////////////////////////////////
/// Populate given frame-slot - intended for initial population
/// of a new slot or low-level window-swapping.
/// No layout or window-mapping is done.
void TEveWindow::PopulateEmptyFrame(TEveCompositeFrame* ef)
{
ef->fEveParent->AddElement(this);
ef->AcquireEveWindow(this);
fEveFrame = ef;
}
////////////////////////////////////////////////////////////////////////////////
/// Swap frames with the given window.
void TEveWindow::SwapWindow(TEveWindow* w)
{
static const TEveException eh("TEveWindow::SwapWindow ");
if (w == nullptr)
throw eh + "Called with null argument.";
SwapWindows(this, w);
}
////////////////////////////////////////////////////////////////////////////////
/// Swap frames with the current window.
void TEveWindow::SwapWindowWithCurrent()
{
static const TEveException eh("TEveWindow::SwapWindowWithCurrent ");
TEveWindow* current = gEve->GetWindowManager()->GetCurrentWindow();
if (current == nullptr)
throw eh + "Current eve-window is not set.";
if (current == this)
throw eh + "This is the current window ... nothing changed.";
SwapWindows(this, current);
}
////////////////////////////////////////////////////////////////////////////////
/// Undock the window - put it into a dedicated main-frame.
void TEveWindow::UndockWindow()
{
TEveWindow* return_cont = fEveFrame->GetEveParentAsWindow();
if (return_cont && ! return_cont->CanMakeNewSlots())
return_cont = nullptr;
// hide slot if in pack
TEveCompositeFrameInPack* packFrame = dynamic_cast<TEveCompositeFrameInPack*>(fEveFrame);
if (packFrame) {
TGPack* pack = (TGPack*)(packFrame->GetParent());
pack->HideFrame(fEveFrame);
}
TEveWindowSlot* ew_slot = TEveWindow::CreateWindowMainFrame(nullptr);
TEveWindow::SwapWindows(ew_slot, this);
((TEveCompositeFrameInMainFrame*) fEveFrame)->
SetOriginalSlotAndContainer(ew_slot, return_cont);
gEve->GetWindowManager()->WindowUndocked(this );
}
////////////////////////////////////////////////////////////////////////////////
/// Undock the window - put it into a dedicated main-frame.
/// The old window slot is destroyed.
void TEveWindow::UndockWindowDestroySlot()
{
TEveWindow* return_cont = fEveFrame->GetEveParentAsWindow();
if (return_cont && ! return_cont->CanMakeNewSlots())
return_cont = nullptr;
TEveWindowSlot* ew_slot = TEveWindow::CreateWindowMainFrame(nullptr);
TEveWindow::SwapWindows(ew_slot, this);
((TEveCompositeFrameInMainFrame*) fEveFrame)->
SetOriginalSlotAndContainer(nullptr, return_cont);
ew_slot->DestroyWindowAndSlot();
gEve->GetWindowManager()->WindowUndocked(this);
}
////////////////////////////////////////////////////////////////////////////////
/// Replace this window with the passed one.
/// Eve parent-ship is properly handled.
/// This will most likely lead to the destruction of this window.
/// Layout is called on the frame.
void TEveWindow::ReplaceWindow(TEveWindow* w)
{
fEveFrame->RelinquishEveWindow();
fEveFrame->fEveParent->AddElement(w);
fEveFrame->AcquireEveWindow(w);
w->fEveFrame = fEveFrame;
fEveFrame->fEveParent->RemoveElement(this);
w->fEveFrame->Layout();
}
////////////////////////////////////////////////////////////////////////////////
/// Destroy eve-window - replace it with an empty frame-slot.
void TEveWindow::DestroyWindow()
{
if (gDebug > 0)
Info("TEveWindow::DestroyWindow()", "name='%s', class='%s', deny-destroy=%d.",
GetElementName(), ClassName(), fDenyDestroy);
if (fEveFrame != nullptr && fDenyDestroy == 1)
{
TEveWindowSlot* ew_slot = TEveWindow::CreateDefaultWindowSlot();
fEveFrame->UnmapWindow();
Bool_t dozrc = fDestroyOnZeroRefCnt;
fDestroyOnZeroRefCnt = kFALSE;
fEveFrame->RelinquishEveWindow();
ew_slot->PopulateEmptyFrame(fEveFrame);
fEveFrame->fEveParent->RemoveElement(this);
fDestroyOnZeroRefCnt = dozrc;
fEveFrame->Layout();
fEveFrame->MapWindow();
fEveFrame = nullptr;
}
TEveElementList::Destroy();
}
////////////////////////////////////////////////////////////////////////////////
/// Destroy eve-window and its frame-slot.
void TEveWindow::DestroyWindowAndSlot()
{
if (gDebug > 0)
Info("TEveWindow::DestroyWindowAndSlot()", "'name=%s', class= '%s', deny-destroy=%d.",
GetElementName(), ClassName(), fDenyDestroy);
if (fEveFrame != nullptr && fDenyDestroy == 1)
{
fEveFrame->RelinquishEveWindow();
fEveFrame->Destroy();
fEveFrame = nullptr;
}
TEveElementList::Destroy();
}
////////////////////////////////////////////////////////////////////////////////
/// Clears eve-frame associated with this window.
/// This is used in special case when the window is embedded in a foreign
/// GUI container and gets deleted from this side.
/// In particular, this happens when TRootBrowser closes a tab.
void TEveWindow::ClearEveFrame()
{
fEveFrame = nullptr;
}
////////////////////////////////////////////////////////////////////////////////
/// Set display state of the title-bar.
/// This is forwarded to eve-frame.
void TEveWindow::SetShowTitleBar(Bool_t x)
{
if (fShowTitleBar == x)
return;
fShowTitleBar = x;
fEveFrame->SetShowTitleBar(fShowTitleBar);
fEveFrame->Layout();
}
////////////////////////////////////////////////////////////////////////////////
/// Returns true if this window is the current one.
Bool_t TEveWindow::IsCurrent() const
{
return gEve->GetWindowManager()->IsCurrentWindow(this);
}
////////////////////////////////////////////////////////////////////////////////
/// Make this window current.
void TEveWindow::MakeCurrent()
{
if ( ! gEve->GetWindowManager()->IsCurrentWindow(this))
gEve->GetWindowManager()->SelectWindow(this);
}
////////////////////////////////////////////////////////////////////////////////
/// Set current state of this eve-window.
/// Protected method - called by window-manager.
void TEveWindow::SetCurrent(Bool_t curr)
{
fEveFrame->SetCurrent(curr);
}
////////////////////////////////////////////////////////////////////////////////
/// Returns true if this is an ancestor of win.
Bool_t TEveWindow::IsAncestorOf(TEveWindow* win)
{
TEveWindow* parent = dynamic_cast<TEveWindow*>(win->fEveFrame->fEveParent);
if (parent)
{
if (parent == this)
return kTRUE;
else
return IsAncestorOf(parent);
}
else
{
return kFALSE;
}
}
////////////////////////////////////////////////////////////////////////////////
/// Slot for clicking on the title-bar.
/// The wish that this window becomes the current one is sent to
/// the window-manager.
void TEveWindow::TitleBarClicked()
{
gEve->GetWindowManager()->SelectWindow(this);
}
////////////////////////////////////////////////////////////////////////////////
/// Create a default window slot.
/// Static helper.
TEveWindowSlot* TEveWindow::CreateDefaultWindowSlot()
{
return new TEveWindowSlot("Free Window Slot", "A free window slot, can become a container or swallow a window.");
}
////////////////////////////////////////////////////////////////////////////////
/// Create a new main-frame and populate it with a default window-slot.
/// The main-frame is mapped.
/// Static helper.
TEveWindowSlot* TEveWindow::CreateWindowMainFrame(TEveWindow* eve_parent)
{
TGMainFrame* mf = new TGMainFrame(gClient->GetRoot(), fgMainFrameDefWidth, fgMainFrameDefHeight);
mf->SetCleanup(kLocalCleanup);
TEveCompositeFrameInMainFrame *slot = new TEveCompositeFrameInMainFrame
(mf, eve_parent, mf);
TEveWindowSlot* ew_slot = TEveWindow::CreateDefaultWindowSlot();
ew_slot->PopulateEmptyFrame(slot);
mf->AddFrame(slot, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
slot->MapWindow();
mf->Layout();
mf->MapWindow();
return ew_slot;
}
////////////////////////////////////////////////////////////////////////////////
/// Create a new tab in a given tab-widget and populate it with a
/// default window-slot.
/// Static helper.