forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TRootGuiBuilder.cxx
2597 lines (2112 loc) · 80.7 KB
/
TRootGuiBuilder.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/guibuilder:$Id: d2f0a1966f9911570cafe9d356f2158a2773edd1 $
// Author: Valeriy Onuchin 12/09/04
/*************************************************************************
* Copyright (C) 1995-2004, 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 "TRootGuiBuilder.h"
#include "TGuiBldDragManager.h"
#include "TGuiBldEditor.h"
#include "TGShutter.h"
#include "TGSplitter.h"
#include "TGLayout.h"
#include "TGResourcePool.h"
#include "TGButton.h"
#include "TROOT.h"
#include "TGDockableFrame.h"
#include "TGMdi.h"
#include "TGStatusBar.h"
#include "TG3DLine.h"
#include "TGLabel.h"
#include "TColor.h"
#include "TGToolBar.h"
#include "TGToolTip.h"
#include "KeySymbols.h"
#include "TGFileDialog.h"
#include "TGMsgBox.h"
#include "TSystem.h"
#include "TApplication.h"
#include "TRootHelpDialog.h"
#include "TGListTree.h"
#include "TImage.h"
#include "TTimer.h"
#include "TGTextEdit.h"
#include "TGTab.h"
#include "TGListBox.h"
#include "TGComboBox.h"
#include "TGProgressBar.h"
//////////////////////////////////////////////////////////////////////////
//
// TRootGuiBuilder
//
//
// ************************************************
// ROOT GUI Builder principles
// ************************************************
//
// With the GUI builder, we try to make the next step from WYSIWYG
// to embedded editing concept - WYSIWYE ("what you see is what you edit").
// The ROOT GUI Builder allows modifying real GUI objects.
// For example, one can edit the existing GUI application created by
// $ROOTSYS/tutorials/gui/guitest.C.
// GUI components can be added to a design area from a widget palette,
// or can be borrowed from another application.
// One can drag and and drop TCanvas's menu bar into the application.
// GUI objects can be resized and dragged, copied and pasted.
// ROOT GUI Builder allows changing the layout, snap to grid, change object's
// layout order via the GUI Builder toolbar, or by options in the right-click
// context menus.
// A final design can be immediatly tested and used, or saved as a C++ macro.
// For example, it's possible to rearrange buttons in control bar,
// add separators etc. and continue to use a new fancy control bar in the
// application.
//
// ************************************************
//
// The following is a short description of the GUI Builder actions and key shortcuts:
//
// o Press Ctrl-Double-Click to start/stop edit mode
// o Press Double-Click to activate quick edit action (defined in root.mimes)
//
// Selection, grabbing, dropping
// ************************************************
// It is possible to select, drag any frame and drop it to any frame
//
// o Click left mouse button or Ctrl-Click to select an object to edit.
// o Press right mouse button to activate context menu
// o Multiple selection (grabbing):
// - draw lasso and press Return key
// - press Shift key and draw lasso
// o Dropping:
// - select frame and press Ctrl-Return key
// o Changing layout order:
// - select frame and use arrow keys to change layout order
// o Alignment:
// - draw lasso and press arrow keys (or Shift-Arrow key) to align frames
//
// Key shortcuts
// ************************************************
// o Return - grab selected frames
// o Ctrl-Return - drop frames
// o Del - delete selected frame
// o Shift-Del - crop action
// o Ctrl-X - cut action
// o Ctrl-C - copy action
// o Ctrl-V - paste frame into the last clicked position
// o Ctrl-L - compact
// o Ctrl-B - enable/disable layout
// o Ctrl-H - switch horizontal-vertical layout
// o Ctrl-G - switch on/off grid
// o Ctrl-S - save action
// o Ctrl-O - open and execute a ROOT macro file. GUI components created
// after macro execution will be emebedded to currently edited
// design area.
// o Ctrl-N - create new main frame
//
//Begin_Html
/*
<img src="gif/RootGuiBuilder.gif">
*/
//End_Html
const char gHelpBuilder[] = "\
Start/Stop Edit Mode\n\
************************************************\n\
o Select File menu / Edit\n\
o Select Start Edit button on the toolbar\n\
o Ctrl-Double-Click on the project frame\n\
o Double-Click to activate quick edit action (defined in root.mimes)\n\
\n\
Select, Grab, Drop\n\
************************************************\n\
It is possible to select & drag any frame and drop it to another frame\n\
\n\
o Press left mouse button Click or Ctrl-Click to select an object.\n\
o Press right mouse button to activate context menu\n\
o Multiple selection can be done in two ways (grabbing):\n\
- draw lasso and press Return key\n\
- press Shift key and draw lasso\n\
o Dropping:\n\
- select frame and press Ctrl-Return key\n\
o Changing layout order of widgets:\n\
- set broken layout mode via toolbar button or check button\n\
\'Layout subframes\' in tab \'Layout\'\n\
- select a widget and use arrow keys to change the layout order\n\
o Alignment:\n\
- remove the selection (if any) by using the space bar\n\
- draw lasso and use the four toolbar buttons for widget alignment\n\
- arrow keys align the frames too, if you prefer the keyboard\n\
\n\
Key shortcuts\n\
************************************************\n\
o Return - grab selected frames\n\
o Ctrl-Return - drop frames\n\
o Del - delete selected frame\n\
o Shift-Del - crop\n\
o Ctrl-X - cut\n\
o Ctrl-C - copy\n\
o Ctrl-V - paste frame into the last clicked position\n\
o Ctrl-L - compact frame\n\
o Ctrl-B - enable/disable layout\n\
o Ctrl-H - switch Horizontal-Vertical layout\n\
o Ctrl-G - switch ON/OFF grid\n\
o Ctrl-S - save\n\
o Ctrl-O - open and execute ROOT macro file\n\
o Ctrl-N - create new main frame\n\
o Ctrl-Z - undo last action (not implemented)\n\
o Shift-Ctrl-Z - redo (not implemented)\n\
\n\
More information\n\
************************************************\n\
\n\
For more information, please see the GuiBuilder Howto page at:\n\
\n\
http://root.cern.ch/root/HowtoGuiBuilder.html\n\
\n\
";
const char gHelpAboutBuilder[] = "\
ROOT Gui Builder\n\
\n\
************************************************************\n\
* Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *\n\
* All rights reserved. *\n\
* *\n\
* For the licensing terms see $ROOTSYS/LICENSE. *\n\
* For the list of contributors see $ROOTSYS/README/CREDITS.*\n\
************************************************************\n\
";
//----- Toolbar stuff...
static ToolBarData_t gToolBarData[] = {
{ "bld_edit.png", "Start Edit (Ctrl-Dbl-Click)", kFALSE, kEditableAct, 0 },
{ "", "", kFALSE, -1, 0 },
{ "bld_new.png", "New (Ctrl-N)", kFALSE, kNewAct, 0 },
{ "bld_open.png", "Open (Ctrl-O)", kFALSE, kOpenAct, 0 },
{ "bld_save.png", "Save As (Ctrl-S)", kFALSE, kSaveAct, 0 },
{ "", "", kFALSE, -1, 0 },
// { "bld_pointer.xpm", "Selector (Ctrl-Click)", kTRUE, kSelectAct, 0 },
// { "bld_grab.xpm", "Grab Selected Frames (Return)", kTRUE, kGrabAct, 0 },
{ "", "", kFALSE, -1, 0 },
{ "bld_compact.png", "Compact selected frame (Ctrl-L)", kFALSE, kCompactAct, 0 },
{ "bld_break.png", "Disable/Enable layout (Ctrl-B)", kFALSE, kBreakLayoutAct, 0 },
{ "bld_hbox.png", "Layout selected frame horizontally (Ctrl-H)", kFALSE, kLayoutHAct, 0 },
{ "bld_vbox.png", "Layout selected frame vertically (Ctrl-H)", kFALSE, kLayoutVAct, 0 },
{ "bld_grid.png", "On/Off grid (Ctrl+G)", kFALSE, kGridAct, 0 },
{ "", "", kFALSE, -1, 0 },
{ "bld_AlignTop.png", "Align selected frames to the top line of lasso (Up Arrow)", kFALSE, kUpAct, 0 },
{ "bld_AlignBtm.png", "Align selected frames to the down line of lasso (Down Arrow)", kFALSE, kDownAct, 0 },
{ "bld_AlignLeft.png", "Align selected frames to the left line of lasso (Left Arrow)", kFALSE, kLeftAct, 0 },
{ "bld_AlignRight.png", "Align selected frames to the right line of lasso (Right Arrow)", kFALSE, kRightAct, 0 },
{ "", "", kFALSE, -1, 0 },
{ "bld_cut.png", "Cut (Ctrl-X)", kFALSE, kCutAct, 0 },
{ "bld_copy.png", "Copy (Ctrl-C)", kFALSE, kCopyAct, 0 },
{ "bld_paste.png", "Paste frame into the last clicked position (Ctrl-V)", kFALSE, kPasteAct, 0 },
// { "bld_paste_into.png", "Paste with replacing of selected frame (Ctrl-R)", kFALSE, kReplaceAct, 0 },
{ "bld_delete.png", "Delete (Del/Backspace)", kFALSE, kDeleteAct, 0 },
{ "bld_crop.png", "Crop (Shift-Del)", kFALSE, kCropAct, 0 },
// { "", "", kFALSE, -1, 0 },
// { "bld_undo.png", "Undo (Ctrl-Z)", kFALSE, kUndoAct, 0 },
// { "bld_redo.png", "Redo (Shift-Ctrl-Z)", kFALSE, kRedoAct, 0 },
{ 0, 0, kFALSE, 0, 0 }
};
ClassImp(TRootGuiBuilder)
TGGC *TRootGuiBuilder::fgBgnd = 0;
TGGC *TRootGuiBuilder::fgBgndPopup = 0;
TGGC *TRootGuiBuilder::fgBgndPopupHlght = 0;
////////////////////////////////////////////////////////////////////////////////
//
// Here are few experimental GUI classes which give a nice&fancy appearence
// to GuiBuilder.
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
class TGuiBldMenuTitle : public TGMenuTitle {
private:
Pixel_t fBgndColor;
protected:
void DoRedraw();
public:
virtual ~TGuiBldMenuTitle() {}
TGuiBldMenuTitle(const TGWindow *p, TGHotString *s, TGPopupMenu *menu) :
TGMenuTitle(p, s, menu) {
fEditDisabled = kEditDisable;
fBgndColor = TRootGuiBuilder::GetBgnd();
SetBackgroundColor(fBgndColor);
AddInput(kEnterWindowMask | kLeaveWindowMask);
}
Bool_t HandleCrossing(Event_t *event);
};
////////////////////////////////////////////////////////////////////////////////
/// Handle crossing events.
Bool_t TGuiBldMenuTitle::HandleCrossing(Event_t *event)
{
if (event->fType == kEnterNotify) {
fBgndColor = TRootGuiBuilder::GetPopupHlght();
} else {
fBgndColor = TRootGuiBuilder::GetBgnd();
}
DoRedraw();
return kTRUE;
}
////////////////////////////////////////////////////////////////////////////////
/// Redraw builder menu title.
void TGuiBldMenuTitle::DoRedraw()
{
TGFrame::DoRedraw();
int x, y, max_ascent, max_descent;
x = y = 4;
gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
if (fState) {
gVirtualX->SetForeground(fNormGC, GetDefaultSelectedBackground());
gVirtualX->FillRectangle(fId,fNormGC, 0, 0, fWidth, fHeight);
gVirtualX->SetForeground(fNormGC, GetForeground());
fLabel->Draw(fId, fSelGC, x, y + max_ascent);
} else {
gVirtualX->SetForeground(fNormGC, fBgndColor);
gVirtualX->FillRectangle(fId,fNormGC, 0, 0, fWidth, fHeight);
gVirtualX->SetForeground(fNormGC, GetForeground());
fLabel->Draw(fId, fNormGC, x, y + max_ascent);
}
if (fBgndColor == TRootGuiBuilder::GetPopupHlght()) {
gVirtualX->DrawRectangle(fId, TGFrame::GetBlackGC()(),
0, 0, GetWidth()-1, GetHeight()-1);
}
}
////////////////////////////////////////////////////////////////////////////////
class TGuiBldPopupMenu : public TGPopupMenu {
public:
virtual ~TGuiBldPopupMenu() { }
TGuiBldPopupMenu() :
TGPopupMenu(gClient->GetDefaultRoot()) {
fEditDisabled = kEditDisable;
SetBackgroundColor(TRootGuiBuilder::GetPopupBgnd());
fEntrySep = 8;
}
void DrawEntry(TGMenuEntry *entry);
};
////////////////////////////////////////////////////////////////////////////////
/// Draw popup menu entry.
void TGuiBldPopupMenu::DrawEntry(TGMenuEntry *entry)
{
FontStruct_t font;
GCValues_t gcval;
if (entry->GetStatus() & kMenuHideMask)
return;
if (entry->GetStatus() & kMenuDefaultMask) {
font = fHifontStruct;
gcval.fMask = kGCFont;
gcval.fFont = gVirtualX->GetFontHandle(font);
gVirtualX->ChangeGC(fNormGC, &gcval);
gVirtualX->ChangeGC(fSelGC, &gcval);
} else {
font = fFontStruct;
}
UInt_t tw = 0;
UInt_t sep = fEntrySep;
Int_t max_ascent, max_descent;
gVirtualX->GetFontProperties(font, max_ascent, max_descent);
if (entry->GetShortcut())
tw = 7 + gVirtualX->TextWidth(fFontStruct, entry->GetShortcutText(),
entry->GetShortcut()->Length());
Int_t tx = entry->GetEx() + fXl;
Int_t ty = entry->GetEy() + max_ascent + 2;
UInt_t h = max_ascent + max_descent + sep;
Int_t picposy = 0;
if (entry->GetPic() != 0) {
picposy = entry->GetEy() + h / 2;
picposy -= entry->GetPic()->GetHeight() / 2;
}
switch (entry->GetType()) {
case kMenuPopup:
case kMenuLabel:
case kMenuEntry:
if ((entry->GetStatus() & kMenuActiveMask) &&
entry->GetType() != kMenuLabel) {
if (entry->GetStatus() & kMenuEnableMask) {
gVirtualX->FillRectangle(fId,
TRootGuiBuilder::GetPopupHlghtGC()->GetGC(),
entry->GetEx()+1, entry->GetEy(),
fMenuWidth-6, h - 1);
gVirtualX->DrawRectangle(fId, TGFrame::GetBlackGC()(),
entry->GetEx()+ 1, entry->GetEy()-1,
fMenuWidth - entry->GetEx()- 6, h - 1);
}
if (entry->GetType() == kMenuPopup) {
DrawTrianglePattern(fSelGC, fMenuWidth-10, entry->GetEy() + 3,
fMenuWidth-6, entry->GetEy() + 11);
}
if (entry->GetStatus() & kMenuCheckedMask) {
DrawCheckMark(fSelGC, 6, entry->GetEy()+sep, 14,
entry->GetEy()+11);
}
if (entry->GetStatus() & kMenuRadioMask) {
DrawRCheckMark(fSelGC, 6, entry->GetEy()+sep, 14,
entry->GetEy()+11);
}
if (entry->GetPic() != 0) {
entry->GetPic()->Draw(fId, fSelGC, 8, picposy);
}
entry->GetLabel()->Draw(fId,
(entry->GetStatus() & kMenuEnableMask) ? fSelGC :
GetShadowGC()(), tx, ty);
if (entry->GetShortcut())
entry->GetShortcut()->Draw(fId,
(entry->GetStatus() & kMenuEnableMask) ? fSelGC :
GetShadowGC()(), fMenuWidth - tw, ty);
} else {
if ( entry->GetType() != kMenuLabel) {
gVirtualX->FillRectangle(fId,
TRootGuiBuilder::GetBgndGC()->GetGC(),
entry->GetEx()+1, entry->GetEy()-1, tx-4, h);
gVirtualX->FillRectangle(fId,
TRootGuiBuilder::GetPopupBgndGC()->GetGC(),
tx-1, entry->GetEy()-1, fMenuWidth-tx-1, h);
} else { // we need some special background for labels
gVirtualX->FillRectangle(fId, TGFrame::GetBckgndGC()(),
entry->GetEx()+1, entry->GetEy()-1,
fMenuWidth - entry->GetEx()- 3, h);
}
if (entry->GetType() == kMenuPopup) {
DrawTrianglePattern(fNormGC, fMenuWidth-10, entry->GetEy() + 3,
fMenuWidth-6, entry->GetEy() + 11);
}
if (entry->GetStatus() & kMenuCheckedMask) {
DrawCheckMark(fNormGC, 6, entry->GetEy()+sep, 14,
entry->GetEy()+11);
}
if (entry->GetStatus() & kMenuRadioMask) {
DrawRCheckMark(fNormGC, 6, entry->GetEy()+sep, 14,
entry->GetEy()+11);
}
if (entry->GetPic() != 0) {
entry->GetPic()->Draw(fId, fNormGC, 8, picposy);
}
if (entry->GetStatus() & kMenuEnableMask) {
entry->GetLabel()->Draw(fId, fNormGC, tx, ty);
if (entry->GetShortcut())
entry->GetShortcut()->Draw(fId, fNormGC, fMenuWidth - tw, ty);
} else {
entry->GetLabel()->Draw(fId, GetHilightGC()(), tx+1, ty+1);
entry->GetLabel()->Draw(fId, GetShadowGC()(), tx, ty);
if (entry->GetShortcut()) {
entry->GetShortcut()->Draw(fId, GetHilightGC()(),
fMenuWidth - tw+1, ty+1);
entry->GetShortcut()->Draw(fId, GetShadowGC()(),
fMenuWidth - tw, ty);
}
}
}
break;
case kMenuSeparator:
gVirtualX->FillRectangle(fId, TRootGuiBuilder::GetBgndGC()->GetGC(),
entry->GetEx()+1, entry->GetEy()-1,
tx-4, 4);
gVirtualX->DrawLine(fId, TGFrame::GetBlackGC()(), tx+1,
entry->GetEy()+1, fMenuWidth-sep,
entry->GetEy()+1);
break;
}
// restore font
if (entry->GetStatus() & kMenuDefaultMask) {
gcval.fFont = gVirtualX->GetFontHandle(fFontStruct);
gVirtualX->ChangeGC(fNormGC, &gcval);
gVirtualX->ChangeGC(fSelGC, &gcval);
}
}
////////////////////////////////////////////////////////////////////////////////
class TGuiBldToolButton : public TGPictureButton {
private:
Pixel_t fBgndColor;
protected:
void DoRedraw();
public:
virtual ~TGuiBldToolButton() { }
TGuiBldToolButton(const TGWindow *p, const TGPicture *pic, Int_t id = -1) :
TGPictureButton(p, pic, id) {
fBgndColor = TRootGuiBuilder::GetBgnd();
ChangeOptions(GetOptions() & ~kRaisedFrame);
}
Bool_t IsDown() const { return (fOptions & kSunkenFrame); }
void SetState(EButtonState state, Bool_t emit = kTRUE);
Bool_t HandleCrossing(Event_t *event);
void SetBackgroundColor(Pixel_t bgnd) { fBgndColor = bgnd; TGFrame::SetBackgroundColor(bgnd); }
};
////////////////////////////////////////////////////////////////////////////////
/// Redraw tool button.
void TGuiBldToolButton::DoRedraw()
{
int x = (fWidth - fTWidth) >> 1;
int y = (fHeight - fTHeight) >> 1;
UInt_t w = GetWidth() - 1;
UInt_t h = GetHeight()- 1;
TGFrame::SetBackgroundColor(fBgndColor);
TGFrame::DoRedraw();
if (fState == kButtonDown || fState == kButtonEngaged) {
++x; ++y;
w--; h--;
}
const TGPicture *pic = fPic;
if (fState == kButtonDisabled) {
if (!fPicD) CreateDisabledPicture();
pic = fPicD ? fPicD : fPic;
}
if (fBgndColor == TRootGuiBuilder::GetPopupHlght()) {
x--; y--;
gVirtualX->DrawRectangle(fId, TGFrame::GetBlackGC()(), 0, 0, w, h);
}
pic->Draw(fId, fNormGC, x, y);
}
////////////////////////////////////////////////////////////////////////////////
/// Handle crossing events.
Bool_t TGuiBldToolButton::HandleCrossing(Event_t *event)
{
if (fTip) {
if (event->fType == kEnterNotify) {
fTip->Reset();
} else {
fTip->Hide();
}
}
if ((event->fType == kEnterNotify) && (fState != kButtonDisabled)) {
fBgndColor = TRootGuiBuilder::GetPopupHlght();
} else {
fBgndColor = TRootGuiBuilder::GetBgnd();
}
if (event->fType == kLeaveNotify) {
fBgndColor = TRootGuiBuilder::GetBgnd();
if (fState != kButtonDisabled && fState != kButtonEngaged)
SetState(kButtonUp, kFALSE);
}
DoRedraw();
return kTRUE;
}
////////////////////////////////////////////////////////////////////////////////
/// Set state of tool bar button and emit a signal according
/// to passed arguments.
void TGuiBldToolButton::SetState(EButtonState state, Bool_t emit)
{
Bool_t was = !IsDown();
if (state != fState) {
switch (state) {
case kButtonEngaged:
case kButtonDown:
fOptions &= ~kRaisedFrame;
fOptions |= kSunkenFrame;
break;
case kButtonDisabled:
case kButtonUp:
fOptions &= ~kRaisedFrame;
fOptions &= ~kSunkenFrame;
break;
}
fState = state;
DoRedraw();
if (emit) EmitSignals(was);
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// Create GUI builder application.
TRootGuiBuilder::TRootGuiBuilder(const TGWindow *p) : TGuiBuilder(),
TGMainFrame(p ? p : gClient->GetDefaultRoot(), 1, 1)
{
SetCleanup(kDeepCleanup);
gGuiBuilder = this;
fManager = 0;
fEditor = 0;
fActionButton = 0;
fClosing = 0;
if (gDragManager) {
fManager = (TGuiBldDragManager *)gDragManager;
} else {
gDragManager = fManager = new TGuiBldDragManager();
}
fManager->SetBuilder(this);
fMenuBar = new TGMdiMenuBar(this, 10, 10);
AddFrame(fMenuBar, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
InitMenu();
AddFrame(new TGHorizontal3DLine(this), new TGLayoutHints(kLHintsTop |
kLHintsExpandX, 0,0,2,2));
fToolDock = new TGDockableFrame(this);
AddFrame(fToolDock, new TGLayoutHints(kLHintsExpandX, 0, 0, 1, 0));
fToolDock->SetWindowName("GuiBuilder ToolBar");
fToolBar = new TGToolBar(fToolDock);
fToolDock->AddFrame(fToolBar, new TGLayoutHints(kLHintsTop |
kLHintsExpandX));
int spacing = 8;
for (int i = 0; gToolBarData[i].fPixmap; i++) {
if (strlen(gToolBarData[i].fPixmap) == 0) {
spacing = 8;
continue;
}
const TGPicture *pic = fClient->GetPicture(gToolBarData[i].fPixmap);
TGuiBldToolButton *pb = new TGuiBldToolButton(fToolBar, pic,
gToolBarData[i].fId);
pb->SetStyle(gClient->GetStyle());
pb->SetToolTipText(gToolBarData[i].fTipText);
TGToolTip *tip = pb->GetToolTip();
tip->SetDelay(200);
tip->Connect("Reset()", "TRootGuiBuilder", this, "UpdateStatusBar(=0)");
tip->Connect("Hide()", "TRootGuiBuilder", this, "EraseStatusBar()");
fToolBar->AddButton(this, pb, spacing);
spacing = 0;
if (gToolBarData[i].fId == kEditableAct) {
fStartButton = pb;
continue;
}
if ((gToolBarData[i].fId == kUndoAct) ||
(gToolBarData[i].fId == kRedoAct)) {
pb->SetState(kButtonDisabled);
}
}
fToolBar->Connect("Clicked(Int_t)", "TGuiBldDragManager", fManager,
"HandleAction(Int_t)");
AddFrame(new TGHorizontal3DLine(this), new TGLayoutHints(kLHintsTop |
kLHintsExpandX, 0,0,2,5));
TGCompositeFrame *cf = new TGHorizontalFrame(this, 1, 1);
AddFrame(cf, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
//fShutterDock = new TGDockableFrame(cf);
//cf->AddFrame(fShutterDock, new TGLayoutHints(kLHintsNormal ));
//fShutterDock->SetWindowName("Widget Factory");
//fShutterDock->EnableUndock(kTRUE);
//fShutterDock->EnableHide(kTRUE);
//fShutterDock->DockContainer();
fShutter = new TGShutter(cf, kSunkenFrame);
cf->AddFrame(fShutter, new TGLayoutHints(kLHintsNormal | kLHintsExpandY));
fShutter->ChangeOptions(fShutter->GetOptions() | kFixedWidth);
TGVSplitter *splitter = new TGVSplitter(cf);
splitter->SetFrame(fShutter, kTRUE);
cf->AddFrame(splitter, new TGLayoutHints(kLHintsLeft | kLHintsExpandY));
fMain = new TGMdiMainFrame(cf, fMenuBar, 1, 1);
fMain->Connect("FrameClosed(Int_t)", "TRootGuiBuilder", this,
"HandleWindowClosed(Int_t)");
TQObject::Connect("TGMdiFrame", "CloseWindow()", "TRootGuiBuilder", this,
"MaybeCloseWindow()");
cf->AddFrame(fMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
fMain->GetContainer()->SetEditDisabled(kEditDisable);
const TGPicture *pbg = fClient->GetPicture("bld_bg.png");
if (pbg) {
fMain->GetContainer()->SetBackgroundPixmap(pbg->GetPicture());
}
if (fManager) {
fEditor = new TGuiBldEditor(cf);
cf->AddFrame(fEditor, new TGLayoutHints(kLHintsNormal | kLHintsExpandY));
fManager->SetPropertyEditor(fEditor);
fEditor->SetEmbedded();
}
AddSection("Projects");
AddSection("Buttons");
AddSection("Containers");
AddSection("Bars");
AddSection("Input");
AddSection("Complex Input");
AddSection("Display");
AddSection("Dialogs");
// create an empty section
AddSection("User's Macros");
TGShutterItem *item = fShutter->GetItem("User's Macros");
TGCompositeFrame *cont = (TGCompositeFrame *)item->GetContainer();
cont->SetBackgroundColor(TColor::Number2Pixel(18));
TGuiBldAction *act = new TGuiBldAction("TGMainFrame", "Empty Frame",
kGuiBldProj);
act->fAct = "empty";
act->fPic = "bld_mainframe.xpm";
AddAction(act, "Projects");
act = new TGuiBldAction("TGMainFrame", "Horizontal Frame", kGuiBldProj);
act->fAct = "horizontal";
act->fPic = "bld_mainframe.xpm";
AddAction(act, "Projects");
act = new TGuiBldAction("TGMainFrame", "Vertical Frame", kGuiBldProj);
act->fAct = "vertical";
act->fPic = "bld_mainframe.xpm";
AddAction(act, "Projects");
// Standard
act = new TGuiBldAction("TGTextButton", "Text Button", kGuiBldCtor);
act->fAct = "new TGTextButton()";
act->fPic = "bld_textbutton.xpm";
AddAction(act, "Buttons");
act = new TGuiBldAction("TGCheckButton", "Check Button", kGuiBldCtor);
act->fAct = "new TGCheckButton()";
act->fPic = "bld_checkbutton.xpm";
AddAction(act, "Buttons");
act = new TGuiBldAction("TGRadioButton", "Radio Button", kGuiBldCtor);
act->fAct = "new TGRadioButton()";
act->fPic = "bld_radiobutton.xpm";
AddAction(act, "Buttons");
act = new TGuiBldAction("TGPictureButton", "Picture Button", kGuiBldCtor);
act->fAct = "new TGPictureButton()";
act->fPic = "bld_image.xpm";
AddAction(act, "Buttons");
act = new TGuiBldAction("TGTextEntry", "Text Entry", kGuiBldCtor);
act->fAct = "new TGTextEntry()";
act->fPic = "bld_entry.xpm";
AddAction(act, "Input");
act = new TGuiBldAction("TGTextEdit", "Text Edit", kGuiBldCtor);
act->fAct = "TRootGuiBuilder::BuildTextEdit()";
act->fPic = "bld_text.xpm";
AddAction(act, "Input");
act = new TGuiBldAction("TGNumberEntry", "Number Entry", kGuiBldCtor);
act->fAct = "new TGNumberEntry()";
act->fPic = "bld_numberentry.xpm";
AddAction(act, "Input");
act = new TGuiBldAction("TGComboBox", "Combo Box", kGuiBldCtor);
act->fAct = "TRootGuiBuilder::BuildComboBox()";
act->fPic = "bld_combobox.xpm";
AddAction(act, "Input");
act = new TGuiBldAction("TGListBox", "List Box", kGuiBldCtor);
act->fAct = "TRootGuiBuilder::BuildListBox()";
act->fPic = "bld_listbox.xpm";
AddAction(act, "Input");
act = new TGuiBldAction("TGHSlider", "Horizontal Slider", kGuiBldCtor);
act->fAct = "new TGHSlider()";
act->fPic = "bld_hslider.xpm";
AddAction(act, "Input");
act = new TGuiBldAction("TGVSlider", "Vertical Slider", kGuiBldCtor);
act->fAct = "new TGVSlider()";
act->fPic = "bld_vslider.xpm";
AddAction(act, "Input");
act = new TGuiBldAction("TGHScrollBar", "HScrollbar", kGuiBldCtor);
act->fAct = "TRootGuiBuilder::BuildHScrollBar()";
act->fPic = "bld_hscrollbar.xpm";
AddAction(act, "Input");
act = new TGuiBldAction("TGVScrollBar", "VScrollbar", kGuiBldCtor);
act->fAct = "TRootGuiBuilder::BuildVScrollBar()";
act->fPic = "bld_vscrollbar.xpm";
AddAction(act, "Input");
act = new TGuiBldAction("TGListTree", "List Tree", kGuiBldCtor);
act->fAct = "TRootGuiBuilder::BuildListTree()";
act->fPic = "bld_listtree.xpm";
AddAction(act, "Complex Input");
act = new TGuiBldAction("TGLabel", "Text Label", kGuiBldCtor);
act->fAct = "new TGLabel()";
act->fPic = "bld_label.xpm";
AddAction(act, "Display");
act = new TGuiBldAction("TGIcon", "Icon", kGuiBldCtor);
act->fAct = "new TGIcon()";
act->fPic = "bld_image.xpm";
AddAction(act, "Display");
act = new TGuiBldAction("TGHorizontal3DLine", "Horizontal Line",
kGuiBldCtor);
act->fAct = "TRootGuiBuilder::BuildH3DLine()";
act->fPic = "bld_hseparator.xpm";
AddAction(act, "Display");
act = new TGuiBldAction("TGVertical3DLine", "Vertical Line", kGuiBldCtor);
act->fAct = "TRootGuiBuilder::BuildV3DLine()";
act->fPic = "bld_vseparator.xpm";
AddAction(act, "Display");
act = new TGuiBldAction("TGStatusBar", "Status Bar", kGuiBldCtor);
act->fAct = "new TGStatusBar()";
act->fPic = "bld_statusbar.xpm";
act->fHints = new TGLayoutHints(kLHintsBottom | kLHintsExpandX);
AddAction(act, "Bars");
act = new TGuiBldAction("TGHProgressBar", "HProgress Bar", kGuiBldCtor);
act->fAct = "TRootGuiBuilder::BuildHProgressBar()";
act->fPic = "bld_hprogressbar.xpm";
AddAction(act, "Display");
act = new TGuiBldAction("TGVProgressBar", "VProgress Bar", kGuiBldCtor);
act->fAct = "TRootGuiBuilder::BuildVProgressBar()";
act->fPic = "bld_vprogressbar.xpm";
AddAction(act, "Display");
act = new TGuiBldAction("TRootEmbeddedCanvas", "Embed Canvas", kGuiBldCtor);
act->fAct = "new TRootEmbeddedCanvas()";
act->fPic = "bld_embedcanvas.xpm";
AddAction(act, "Display");
// Containers
act = new TGuiBldAction("TGHorizontalFrame", "Horizontal Frame",
kGuiBldCtor);
act->fAct = "new TGHorizontalFrame(0,200,100)";
act->fPic = "bld_hbox.xpm";
AddAction(act, "Containers");
act = new TGuiBldAction("TGVerticalFrame", "Vertical Frame", kGuiBldCtor);
act->fAct = "new TGVerticalFrame(0,100,200)";
act->fPic = "bld_vbox.xpm";
AddAction(act, "Containers");
act = new TGuiBldAction("TGGroupFrame", "Group Frame", kGuiBldCtor);
act->fAct = "new TGGroupFrame()";
act->fPic = "bld_groupframe.xpm";
AddAction(act, "Containers");
act = new TGuiBldAction("TGTab", "Tabbed Frame", kGuiBldCtor);
act->fAct = "TRootGuiBuilder::BuildTab()";
act->fPic = "bld_tab.xpm";
AddAction(act, "Containers");
act = new TGuiBldAction("TGShutter", "Shutter", kGuiBldCtor);
act->fAct = "TRootGuiBuilder::BuildShutter()";
act->fPic = "bld_shutter.png";
AddAction(act, "Containers");
act = new TGuiBldAction("TGCanvas", "Scrolled Canvas", kGuiBldCtor);
act->fAct = "TRootGuiBuilder::BuildCanvas()";
act->fPic = "bld_canvas.xpm";
AddAction(act, "Containers");
/*
act = new TGuiBldAction("TGVSplitter", "Horizontal Panes", kGuiBldFunc);
act->fAct = "TRootGuiBuilder::VSplitter()";
act->fPic = "bld_hpaned.xpm";
AddAction(act, "Containers");
act = new TGuiBldAction("TGHSplitter", "Vertical Panes", kGuiBldFunc);
act->fAct = "TRootGuiBuilder::HSplitter()";
act->fPic = "bld_vpaned.xpm";
AddAction(act, "Containers");
*/
act = new TGuiBldAction("TGColorSelect", "Color Selector", kGuiBldFunc);
act->fAct = "new TGColorSelect()";
act->fPic = "bld_colorselect.xpm";
AddAction(act, "Dialogs");
fShutter->Resize(140, fShutter->GetHeight());
fStatusBar = new TGStatusBar(this, 40, 10);
AddFrame(fStatusBar, new TGLayoutHints(kLHintsBottom | kLHintsExpandX,
0, 0, 3, 0));
PropagateBgndColor(this, GetBgnd());
SetEditDisabled(kEditDisable); // disable editting to all subframes
MapSubwindows();
Int_t qq;
UInt_t ww;
UInt_t hh;
gVirtualX->GetWindowSize(gVirtualX->GetDefaultRootWindow(), qq, qq, ww, hh);
MoveResize(100, 100, ww - 200, hh - 200);
SetWMPosition(100, 100);
SetWindowName("ROOT GuiBuilder");
SetIconName("ROOT GuiBuilder");
fIconPic = SetIconPixmap("bld_rgb.xpm");
SetClassHints("ROOT", "GuiBuilder");
fSelected = 0;
Update();
fMenuFile->Connect("Activated(Int_t)", "TRootGuiBuilder", this,
"HandleMenu(Int_t)");
fMenuWindow->Connect("Activated(Int_t)", "TRootGuiBuilder", this,
"HandleMenu(Int_t)");
fMenuHelp->Connect("Activated(Int_t)", "TRootGuiBuilder", this,
"HandleMenu(Int_t)");
// doesn't work properly on Windows...
if (gVirtualX->InheritsFrom("TGX11"))
BindKeys();
UpdateStatusBar("Ready");
MapRaised();
fEditor->SwitchLayout();
}
////////////////////////////////////////////////////////////////////////////////
/// Destructor.
TRootGuiBuilder::~TRootGuiBuilder()
{
if (fIconPic) gClient->FreePicture(fIconPic);
delete fMenuFile;
delete fMenuWindow;
delete fMenuHelp;
gGuiBuilder = 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Close GUI builder via window manager "Close" button.
void TRootGuiBuilder::CloseWindow()
{
TGWindow *root = (TGWindow*)fClient->GetRoot();
if (root) root->SetEditable(kFALSE);
fEditor->Reset();
if (fMain->GetNumberOfFrames() == 0) {
fMenuFile->DisableEntry(kGUIBLD_FILE_CLOSE);
fMenuFile->DisableEntry(kGUIBLD_FILE_STOP);
fMenuFile->DisableEntry(kGUIBLD_FILE_START);
} else {
fMenuFile->DisableEntry(kGUIBLD_FILE_STOP);
fMenuFile->EnableEntry(kGUIBLD_FILE_START);
fMenuFile->EnableEntry(kGUIBLD_FILE_CLOSE);
}
TGButton *btn = fToolBar->GetButton(kGridAct);
if (btn) {
btn->SetState(!fClient->IsEditable() ? kButtonDisabled : kButtonUp);
}
fClosing = 1;
fMain->CloseAll();
if (fClosing == -1) {
fClosing = 0;
return;
}
SwitchToolbarButton();
Hide();
}
////////////////////////////////////////////////////////////////////////////////
/// Find action by name
TGButton *TRootGuiBuilder::FindActionButton(const char *name, const char *sect)
{
if (!name || !sect) return 0;
TGShutterItem *item = fShutter->GetItem(sect);
if (!item) return 0;
TGCompositeFrame *cont = (TGCompositeFrame *)item->GetContainer();
TGHorizontalFrame *hf;
TGFrameElement *fe;
TIter next(cont->GetList());
TGLabel *lb;
TGButton *btn;
while ((fe = (TGFrameElement*)next())) {
hf = (TGHorizontalFrame*)fe->fFrame;
btn = (TGButton*)((TGFrameElement*)hf->GetList()->First())->fFrame;
lb = (TGLabel*)((TGFrameElement*)hf->GetList()->Last())->fFrame;
if (*(lb->GetText()) == name) {
return (TGButton*)btn;
}