forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TGuiBldDragManager.cxx
6332 lines (5103 loc) · 173 KB
/
TGuiBldDragManager.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: 99541fed972db7e4279fadcd4c0a0f0ae28a0a4d $
// 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 "TGuiBldDragManager.h"
#include "TGuiBldEditor.h"
#include "TRootGuiBuilder.h"
#include "TTimer.h"
#include "TList.h"
#include "TClass.h"
#include "TSystem.h"
#include "TROOT.h"
#include "TColor.h"
#include "TImage.h"
#include "TError.h"
#include "TClassMenuItem.h"
#include "TMethod.h"
#include "TBaseClass.h"
#include "TMethodArg.h"
#include "TToggle.h"
#include "TDataType.h"
#include "TObjString.h"
#include "TInterpreter.h"
#include "KeySymbols.h"
#include "TGResourcePool.h"
#include "TGMenu.h"
#include "TGFileDialog.h"
#include "TGMsgBox.h"
#include "TRandom.h"
#include "TGButton.h"
#include "TGMdi.h"
#include "TGTextEntry.h"
#include "TGDockableFrame.h"
#include "TGColorDialog.h"
#include "TGFontDialog.h"
#include "TGComboBox.h"
#include "TGCanvas.h"
#include "TGLabel.h"
#include "TGProgressBar.h"
#include "TGScrollBar.h"
#include "TGTextEntry.h"
#undef DEBUG_LOCAL
//_____________________________________________________________________________
//
// TGuiBldDragManager
//
// Drag and drop manager used by the ROOT GUI Builder.
//_____________________________________________________________________________
ClassImp(TGuiBldDragManager)
static UInt_t gGridStep = 8;
static TGuiBldDragManager *gGuiBldDragManager = 0;
TGColorDialog *TGuiBldDragManager::fgGlobalColorDialog = 0;
TGFontDialog *TGuiBldDragManager::fgGlobalFontDialog = 0;
static const char *gSaveMacroTypes[] = {
"Macro files", "*.C",
"All files", "*",
0, 0
};
static const char *gImageTypes[] = {
"All files", "*",
"XPM", "*.xpm",
"GIF", "*.gif",
"PNG", "*.png",
"JPEG", "*.jpg",
"TARGA", "*.tga",
"BMP", "*.bmp",
"ICO", "*.ico",
"XCF", "*.xcf",
"CURSORS", "*.cur",
"PPM", "*.ppm",
"PNM", "*.pnm",
"XBM", "*.xbm",
"TIFF", "*.tiff",
"Enacapsulated PostScript", "*.eps",
"PostScript", "*.ps",
"PDF", "*.pdf",
"ASImage XML","*.xml",
0, 0
};
////////////////////////////////////////////////////////////////////////////////
class TGuiBldMenuDialog : public TGTransientFrame {
friend class TGuiBldDragManager;
public:
TGButton *fOK; // OK button
//TGButton *fApply; // apply button
TGButton *fCancel; // cancel button
TObject *fObject; // selected object/frame
TMethod *fMethod; // method to be applied
TGLayoutHints *fL1; // internally used layout hints
TGLayoutHints *fL2; // internally used layout hints
TList *fWidgets; // list of widgets
public:
virtual ~TGuiBldMenuDialog();
TGuiBldMenuDialog(const TGWindow *main, TObject *obj, TMethod *method);
const char *GetParameters();
void CloseWindow();
void ConnectButtonSignals();
void Build();
void Popup();
void ApplyMethod();
void Add(const char *argname, const char *value, const char *type);
};
static TGuiBldMenuDialog *gMenuDialog = 0;
////////////////////////////////////////////////////////////////////////////////
/// ctor.
TGuiBldMenuDialog::TGuiBldMenuDialog(const TGWindow *main, TObject *obj, TMethod *method) :
TGTransientFrame(gClient->GetDefaultRoot(), main, 200, 100)
{
fObject = obj;
fMethod = method;
if (!obj) return; // zombie
fWidgets = new TList();
fL1 = new TGLayoutHints(kLHintsTop | kLHintsCenterX, 0, 0, 5, 0);
fL2 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
TString title = obj->ClassName();
title += "::";
title += method->GetName();
Build();
ConnectButtonSignals();
SetWindowName(title);
SetIconName(title);
SetEditDisabled(kEditDisable);
//TRootGuiBuilder::PropagateBgndColor(this, TRootGuiBuilder::GetBgnd());
}
////////////////////////////////////////////////////////////////////////////////
/// dtor.
TGuiBldMenuDialog::~TGuiBldMenuDialog()
{
fWidgets->Delete();
delete fWidgets;
delete fL1;
delete fL2;
}
////////////////////////////////////////////////////////////////////////////////
/// Connect buttons signals
void TGuiBldMenuDialog::ConnectButtonSignals()
{
fOK->Connect("Pressed()", "TGuiBldDragManager", gGuiBldDragManager, "DoDialogOK()");
//fApply->Connect("Pressed()", "TGuiBldDragManager", gGuiBldDragManager, "DoDialogApply()");
fCancel->Connect("Pressed()", "TGuiBldDragManager", gGuiBldDragManager, "DoDialogCancel()");
}
////////////////////////////////////////////////////////////////////////////////
/// execute method for obejct with input args
void TGuiBldMenuDialog::ApplyMethod()
{
const char *params = GetParameters();
fObject->Execute(fMethod->GetName(), params);
}
////////////////////////////////////////////////////////////////////////////////
/// Return input parameters as single string.
const char *TGuiBldMenuDialog::GetParameters()
{
static char params[1024];
char param[256];
TObjString *str;
TObject *obj;
Int_t selfobjpos;
// if (fMenu->GetContextMenu()->GetSelectedMenuItem())
// selfobjpos = fMenu->GetContextMenu()->GetSelectedMenuItem()->GetSelfObjectPos();
// else
selfobjpos = -1;
params[0] = 0;
TIter next(fWidgets);
Int_t nparam = 0;
while ((obj = next())) { // first element is label, skip...
if (obj->IsA() != TGLabel::Class()) break;
obj = next(); // get either TGTextEntry or TGComboBox
str = (TObjString *) next(); // get type string
nparam++;
const char *type = str->GetString().Data();
const char *data = 0;
if (obj->IsA() == TGTextEntry::Class())
data = ((TGTextEntry *) obj)->GetBuffer()->GetString();
// TODO: Combobox...
// if necessary, replace the selected object by it's address
if (selfobjpos == nparam-1) {
if (params[0]) strlcat(params, ",", 1024-strlen(params));
snprintf(param, 255, "(TObject*)0x%lx", (Long_t)fObject);
strlcat(params, param, 1024-strlen(params));
}
if (params[0]) strlcat(params, ",", 1024-strlen(params));
if (data) {
if (!strncmp(type, "char*", 5))
snprintf(param, 255, "\"%s\"", data);
else
strlcpy(param, data, sizeof(param));
} else
strlcpy(param, "0", sizeof(param));
strlcat(params, param, 1024-strlen(params));
}
// if selected object is the last argument, have to insert it here
if (selfobjpos == nparam) {
if (params[0]) strlcat(params, ",", 1024-strlen(params));
snprintf(param, 255, "(TObject*)0x%lx", (Long_t)fObject);
strlcat(params, param, 1024-strlen(params));
}
return params;
}
////////////////////////////////////////////////////////////////////////////////
/// Create a string describing method argument.
static TString CreateArgumentTitle(TMethodArg *argument)
{
static TString ret;
if (argument) {
ret.Form("(%s) %s", argument->GetTitle(), argument->GetName());
if (argument->GetDefault() && *(argument->GetDefault())) {
ret += " [default: ";
ret += argument->GetDefault();
ret += "]";
}
}
return ret;
}
////////////////////////////////////////////////////////////////////////////////
/// Add a label and text input field.
void TGuiBldMenuDialog::Add(const char *argname, const char *value, const char *type)
{
TGLabel *l = new TGLabel(this, argname);
TGTextBuffer *b = new TGTextBuffer(20);
b->AddText(0, value);
TGTextEntry *t = new TGTextEntry(this, b);
t->Connect("ReturnPressed()", "TGuiBldDragManager", gGuiBldDragManager, "DoDialogOK()");
t->Resize(260, t->GetDefaultHeight());
AddFrame(l, fL1);
AddFrame(t, fL2);
fWidgets->Add(l);
fWidgets->Add(t);
fWidgets->Add(new TObjString(type));
}
////////////////////////////////////////////////////////////////////////////////
/// Close window
void TGuiBldMenuDialog::CloseWindow()
{
gGuiBldDragManager->DoDialogCancel();
}
////////////////////////////////////////////////////////////////////////////////
/// Build dialog
void TGuiBldMenuDialog::Build()
{
TMethodArg *argument = 0;
Int_t selfobjpos = -1;
TIter next(fMethod->GetListOfMethodArgs());
Int_t argpos = 0;
while ((argument = (TMethodArg *) next())) {
// Do not input argument for self object
if (selfobjpos != argpos) {
TString arg_name = CreateArgumentTitle(argument);
const char *argname = arg_name.Data();
const char *type = argument->GetTypeName();
TDataType *datatype = gROOT->GetType(type);
const char *charstar = "char*";
char basictype[32];
if (datatype) {
strlcpy(basictype, datatype->GetTypeName(), sizeof(basictype));
} else {
TClass *cl = TClass::GetClass(type);
if (strncmp(type, "enum", 4) && (cl && !(cl->Property() & kIsEnum)))
Warning("Dialog", "data type is not basic type, assuming (int)");
strlcpy(basictype, "int", sizeof(basictype));
}
if (strchr(argname, '*')) {
strlcat(basictype, "*", 32-strlen(basictype));
type = charstar;
}
TDataMember *m = argument->GetDataMember();
if (m && m->GetterMethod(fObject->IsA())) {
// Get the current value and form it as a text:
char val[256];
if (!strncmp(basictype, "char*", 5)) {
char *tdefval = 0;
m->GetterMethod()->Execute(fObject, "", &tdefval);
if (tdefval && strlen(tdefval))
strlcpy(val, tdefval, sizeof(val));
} else if (!strncmp(basictype, "float", 5) ||
!strncmp(basictype, "double", 6)) {
Double_t ddefval = 0.0;
m->GetterMethod()->Execute(fObject, "", ddefval);
snprintf(val, 255, "%g", ddefval);
} else if (!strncmp(basictype, "char", 4) ||
!strncmp(basictype, "bool", 4) ||
!strncmp(basictype, "int", 3) ||
!strncmp(basictype, "long", 4) ||
!strncmp(basictype, "short", 5)) {
Long_t ldefval = 0L;
m->GetterMethod()->Execute(fObject, "", ldefval);
snprintf(val, 255, "%li", ldefval);
}
// Find out whether we have options ...
TList *opt;
// coverity[returned_pointer]: keep for later use
if ((opt = m->GetOptions())) {
Warning("Dialog", "option menu not yet implemented");
} else {
// we haven't got options - textfield ...
Add(argname, val, type);
}
} else { // if m not found ...
char val[256] = "";
const char *tval = argument->GetDefault();
if (tval) strlcpy(val, tval, sizeof(val));
Add(argname, val, type);
}
}
argpos++;
}
// add OK, Apply, Cancel buttons
TGHorizontalFrame *hf = new TGHorizontalFrame(this, 60, 20, kFixedWidth);
TGLayoutHints *l1 = new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 5, 5, 0, 0);
UInt_t width = 0, height = 0;
fWidgets->Add(l1);
fOK = new TGTextButton(hf, "&OK", 1);
hf->AddFrame(fOK, l1);
fWidgets->Add(fOK);
height = fOK->GetDefaultHeight();
width = TMath::Max(width, fOK->GetDefaultWidth());
/*
fApply = new TGTextButton(hf, "&Apply", 2);
hf->AddFrame(fApply, l1);
fWidgets->Add(fApply);
height = fApply->GetDefaultHeight();
width = TMath::Max(width, fApply->GetDefaultWidth());
*/
fCancel = new TGTextButton(hf, "&Cancel", 3);
hf->AddFrame(fCancel, l1);
fWidgets->Add(fCancel);
height = fCancel->GetDefaultHeight();
width = TMath::Max(width, fCancel->GetDefaultWidth());
// place buttons at the bottom
l1 = new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5);
AddFrame(hf, l1);
fWidgets->Add(l1);
fWidgets->Add(hf);
hf->Resize((width + 20) * 3, height);
// map all widgets and calculate size of dialog
MapSubwindows();
}
////////////////////////////////////////////////////////////////////////////////
/// Popup dialog.
void TGuiBldMenuDialog::Popup()
{
UInt_t width = GetDefaultWidth();
UInt_t height = GetDefaultHeight();
Resize(width, height);
Window_t wdummy;
Int_t x = (Int_t)((TGFrame*)fMain)->GetWidth();
Int_t y = (Int_t)((TGFrame*)fMain)->GetHeight();
gVirtualX->TranslateCoordinates(fMain->GetId(), fClient->GetDefaultRoot()->GetId(),
x, y, x, y, wdummy);
x += 10;
y += 10;
// make the message box non-resizable
SetWMSize(width, height);
SetWMSizeHints(width, height, width, height, 0, 0);
SetMWMHints(kMWMDecorAll | kMWMDecorResizeH | kMWMDecorMaximize |
kMWMDecorMinimize | kMWMDecorMenu,
kMWMFuncAll | kMWMFuncResize | kMWMFuncMaximize |
kMWMFuncMinimize,
kMWMInputModeless);
Move(x, y);
SetWMPosition(x, y);
MapRaised();
fClient->WaitFor(this);
}
///////////////////////// auxilary static functions ///////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// Helper. Return a window located at point x,y (in screen coordinates)
static Window_t GetWindowFromPoint(Int_t x, Int_t y)
{
Window_t src, dst, child;
Window_t ret = 0;
Int_t xx = x;
Int_t yy = y;
if (!gGuiBldDragManager || gGuiBldDragManager->IsStopped() ||
!gClient->IsEditable()) return 0;
dst = src = child = gVirtualX->GetDefaultRootWindow();
while (child && dst) {
src = dst;
dst = child;
gVirtualX->TranslateCoordinates(src, dst, xx, yy, xx, yy, child);
ret = dst;
}
return ret;
}
////////////////////////////////////////////////////////////////////////////////
/// Helper to layout
static void layoutFrame(TGFrame *frame)
{
if (!frame || !frame->InheritsFrom(TGCompositeFrame::Class())) {
return;
}
TGCompositeFrame *comp = (TGCompositeFrame*)frame;
if (comp->GetLayoutManager()) {
comp->GetLayoutManager()->Layout();
} else {
comp->Layout();
}
gClient->NeedRedraw(comp);
TIter next(comp->GetList());
TGFrameElement *fe;
while ((fe = (TGFrameElement*)next())) {
layoutFrame(fe->fFrame);
gClient->NeedRedraw(fe->fFrame);
}
}
////////////////////////////////////////////////////////////////////////////////
/// Our own error handler (not used yet)
static void GuiBldErrorHandler(Int_t /*level*/, Bool_t /*abort*/,
const char * /*location*/, const char * /*msg*/)
{
}
////////////////////////////////////////////////////////////////////////////////
class TGuiBldDragManagerGrid {
public:
static UInt_t fgStep;
static ULong_t fgPixel;
static TGGC *fgBgnd;
Pixmap_t fPixmap;
TGWindow *fWindow;
Int_t fWinId;
TGuiBldDragManagerGrid();
~TGuiBldDragManagerGrid();
void Draw();
void SetStep(UInt_t step);
void InitPixmap();
void InitBgnd();
};
UInt_t TGuiBldDragManagerGrid::fgStep = gGridStep;
ULong_t TGuiBldDragManagerGrid::fgPixel = 0;
TGGC *TGuiBldDragManagerGrid::fgBgnd = 0;
////////////////////////////////////////////////////////////////////////////////
/// Create a grid background for the selected window
TGuiBldDragManagerGrid::TGuiBldDragManagerGrid()
{
fPixmap = 0;
fWindow = 0;
fWinId = 0;
if (!fgBgnd) {
InitBgnd();
}
SetStep(fgStep);
}
////////////////////////////////////////////////////////////////////////////////
/// ctor.
TGuiBldDragManagerGrid::~TGuiBldDragManagerGrid()
{
fWindow = gClient->GetWindowById(fWinId);
if (fWindow) {
fWindow->SetBackgroundPixmap(0);
fWindow->SetBackgroundColor(((TGFrame*)fWindow)->GetBackground());
gClient->NeedRedraw(fWindow, kTRUE);
}
if (fPixmap) {
gVirtualX->DeletePixmap(fPixmap);
}
fPixmap = 0;
fWindow = 0;
fWinId = 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Set the grid step
void TGuiBldDragManagerGrid::SetStep(UInt_t step)
{
if (!gClient || !gClient->IsEditable()) {
return;
}
fWindow = (TGWindow*)gClient->GetRoot();
fWinId = fWindow->GetId();
fgStep = step;
InitPixmap();
}
////////////////////////////////////////////////////////////////////////////////
/// Create grid background.
void TGuiBldDragManagerGrid::InitBgnd()
{
if (fgBgnd) {
return;
}
fgBgnd = new TGGC(TGFrame::GetBckgndGC());
Float_t r, g, b;
r = 232./255;
g = 232./255;
b = 226./255;
fgPixel = TColor::RGB2Pixel(r, g, b);
fgBgnd->SetForeground(fgPixel);
}
////////////////////////////////////////////////////////////////////////////////
/// Create grid background pixmap
void TGuiBldDragManagerGrid::InitPixmap()
{
if (fPixmap) {
gVirtualX->DeletePixmap(fPixmap);
}
fPixmap = gVirtualX->CreatePixmap(gClient->GetDefaultRoot()->GetId(), fgStep, fgStep);
gVirtualX->FillRectangle(fPixmap, fgBgnd->GetGC(), 0, 0, fgStep, fgStep);
if(fgStep > 2) {
gVirtualX->FillRectangle(fPixmap, TGFrame::GetShadowGC()(),
fgStep - 1, fgStep - 1, 1, 1);
}
}
////////////////////////////////////////////////////////////////////////////////
/// Draw grid over editted frame.
void TGuiBldDragManagerGrid::Draw()
{
if (!gClient || !gClient->IsEditable()) {
return;
}
fWindow = gClient->GetWindowById(fWinId);
if (fWindow && (fWindow != gClient->GetRoot())) {
fWindow->SetBackgroundPixmap(0);
fWindow->SetBackgroundColor(((TGFrame*)fWindow)->GetBackground());
gClient->NeedRedraw(fWindow);
}
if (!fPixmap) {
InitPixmap();
}
fWindow = (TGWindow*)gClient->GetRoot();
fWinId = fWindow->GetId();
fWindow->SetBackgroundPixmap(fPixmap);
gClient->NeedRedraw(fWindow);
}
////////////////////////////////////////////////////////////////////////////////
class TGuiBldDragManagerRepeatTimer : public TTimer {
private:
TGuiBldDragManager *fManager; // back pointer
public:
TGuiBldDragManagerRepeatTimer(TGuiBldDragManager *m, Long_t ms) :
TTimer(ms, kTRUE) { fManager = m; }
Bool_t Notify() { fManager->HandleTimer(this); Reset(); return kFALSE; }
};
////////////////////////////////////////////////////////////////////////////////
class TGGrabRect : public TGFrame {
private:
Pixmap_t fPixmap;
ECursor fType;
public:
TGGrabRect(Int_t type);
~TGGrabRect() {}
Bool_t HandleButton(Event_t *ev);
ECursor GetType() const { return fType; }
};
////////////////////////////////////////////////////////////////////////////////
/// ctor.
TGGrabRect::TGGrabRect(Int_t type) :
TGFrame(gClient->GetDefaultRoot(), 8, 8, kTempFrame)
{
fType = kTopLeft;
switch (type) {
case 0:
fType = kTopLeft;
break;
case 1:
fType = kTopSide;
break;
case 2:
fType = kTopRight;
break;
case 3:
fType = kBottomLeft;
break;
case 4:
fType = kLeftSide;
break;
case 5:
fType = kRightSide;
break;
case 6:
fType = kBottomSide;
break;
case 7:
fType = kBottomRight;
break;
}
SetWindowAttributes_t attr;
attr.fMask = kWAOverrideRedirect | kWASaveUnder;
attr.fOverrideRedirect = kTRUE;
attr.fSaveUnder = kTRUE;
gVirtualX->ChangeWindowAttributes(fId, &attr);
fPixmap = gVirtualX->CreatePixmap(gVirtualX->GetDefaultRootWindow(), 8, 8);
const TGGC *bgc = TRootGuiBuilder::GetPopupHlghtGC();
//fClient->GetResourcePool()->GetSelectedBckgndGC();
TGGC *gc = new TGGC(TGFrame::GetBckgndGC());
Pixel_t back;
fClient->GetColorByName("black", back);
gc->SetBackground(back);
gc->SetForeground(back);
gVirtualX->FillRectangle(fPixmap, bgc->GetGC(), 0, 0, 7, 7);
gVirtualX->DrawRectangle(fPixmap, gc->GetGC(), 0, 0, 7, 7);
// gVirtualX->DrawRectangle(fPixmap, fClient->GetResourcePool()->GetSelectedBckgndGC()->GetGC(), 1, 1, 5, 5);
AddInput(kButtonPressMask);
SetBackgroundPixmap(fPixmap);
gVirtualX->SetCursor(fId, gVirtualX->CreateCursor(fType));
}
////////////////////////////////////////////////////////////////////////////////
/// Handle button press event.
Bool_t TGGrabRect::HandleButton(Event_t *ev)
{
gGuiBldDragManager->CheckDragResize(ev);
return kTRUE;
}
////////////////////////////////////////////////////////////////////////////////
class TGAroundFrame : public TGFrame {
public:
TGAroundFrame();
~TGAroundFrame() {}
};
////////////////////////////////////////////////////////////////////////////////
/// ctor.
TGAroundFrame::TGAroundFrame() : TGFrame(gClient->GetDefaultRoot(), 1, 1,
kTempFrame | kOwnBackground)
{
SetWindowAttributes_t attr;
attr.fMask = kWAOverrideRedirect | kWASaveUnder;
attr.fOverrideRedirect = kTRUE;
attr.fSaveUnder = kTRUE;
gVirtualX->ChangeWindowAttributes(fId, &attr);
ULong_t blue;
fClient->GetColorByName("blue", blue);
SetBackgroundColor(blue);
}
////////////////////////////////////////////////////////////////////////////////
class TGuiBldDragManagerPimpl {
friend class TGuiBldDragManager;
private:
TGuiBldDragManager *fManager; // drag and drop manager
TTimer *fRepeatTimer; // repeat rate timer (when mouse stays pressed)
TGFrame *fGrab; // grabbed/selected frame
TGLayoutHints *fGrabLayout; // layout of grabbed frame
TGFrame *fSaveGrab; // used during context menu handling
TGFrame *fClickFrame; // last clicked frame
TGuiBldDragManagerGrid *fGrid; //
ECursor fResizeType; // defines resize type
Int_t fX0, fY0; // initial drag position in pixels
Int_t fX, fY; // current drag position in pixels
Int_t fXf, fYf; // offset of inititial position inside frame
Int_t fGrabX, fGrabY; //
const TGWindow *fGrabParent; // parent of the grabbed/seleceted frame
Int_t fLastPopupAction;//
Bool_t fReplaceOn;
TGGrabRect *fGrabRect[8]; // small rectangles drawn over grabbed/selected frame
TGFrame *fAroundFrame[4]; // red lines drawn over layouted frame
Bool_t fGrabRectHidden;
TGFrameElement *fGrabListPosition;
Bool_t fButtonPressed; //
Bool_t fCompacted; //
TGFrame *fPlane; // highlighted plain composite frame when mose is moving
TGFrame *fSpacePressedFrame; // frame which was grabbed via spacebar pressed
Bool_t fPlacePopup; // kTRUE is menu fo frame was placed
TList *fFrameMenuTrash; // trash list
TGFrame *fMenuObject; // object/frame for which context menu is created
public:
TGuiBldDragManagerPimpl(TGuiBldDragManager *m) {
fManager = m;
fRepeatTimer = new TGuiBldDragManagerRepeatTimer(m, 100);
int i = 0;
for (i = 0; i <8; i++) {
fGrabRect[i] = new TGGrabRect(i);
}
for (i = 0; i <4; i++) {
fAroundFrame[i] = new TGAroundFrame();
}
fFrameMenuTrash = new TList();
ResetParams();
}
void ResetParams() {
fGrab = 0;
fSaveGrab = 0;
fClickFrame = 0;
fGrid = 0;
fX0 = fY0 = fX = fY = fXf = fYf = fGrabX = fGrabY = 0;
fGrabParent = 0;
fResizeType = kPointer;
fLastPopupAction = kNoneAct;
fReplaceOn = kFALSE;
fGrabLayout = 0;
fGrabRectHidden = kFALSE;
fGrabListPosition = 0;
fButtonPressed = kFALSE;
fCompacted = kFALSE;
fPlane = 0;
fSpacePressedFrame = 0;
fPlacePopup = kFALSE;
fFrameMenuTrash->Delete();
fMenuObject = 0;
}
~TGuiBldDragManagerPimpl() {
int i;
for (i = 0; i <8; i++) {
delete fGrabRect[i];
}
for (i = 0; i <4; i++) {
delete fAroundFrame[i];
}
delete fRepeatTimer;
delete fGrab;
fFrameMenuTrash->Delete();
delete fFrameMenuTrash;
if (fPlane) {
fPlane->ChangeOptions(fPlane->GetOptions() & ~kRaisedFrame);
gClient->NeedRedraw(fPlane, kTRUE);
fPlane = 0;
}
}
};
////////////////////////////////////////////////////////////////////////////////
TGuiBldDragManager::TGuiBldDragManager() : TVirtualDragManager() ,
TGFrame(gClient->GetDefaultRoot(), 1, 1)
{
// Constructor. Create "fantom window".
SetWindowAttributes_t attr;
attr.fMask = kWAOverrideRedirect | kWASaveUnder;
attr.fOverrideRedirect = kTRUE;
attr.fSaveUnder = kTRUE;
gVirtualX->ChangeWindowAttributes(fId, &attr);
gGuiBldDragManager = this;
fPimpl = new TGuiBldDragManagerPimpl(this);
fSelectionIsOn = kFALSE;
fFrameMenu = 0;
fLassoMenu = 0;
fEditor = 0;
fBuilder = 0;
fLassoDrawn = kFALSE;
fDropStatus = kFALSE;
fStop = kTRUE;
fSelected = 0;
fListOfDialogs = 0;
Reset1();
CreateListOfDialogs();
TString tmpfile = gSystem->TempDirectory();
char *s = gSystem->ConcatFileName(tmpfile.Data(),
TString::Format("RootGuiBldClipboard%d.C", gSystem->GetPid()));
fPasteFileName = s;
delete [] s;
s = gSystem->ConcatFileName(tmpfile.Data(),
TString::Format("RootGuiBldTmpFile%d.C", gSystem->GetPid()));
fTmpBuildFile = s;
delete [] s;
fName = "Gui Builder Drag Manager";
SetWindowName(fName.Data());
// let's try to solve the problems by myself
SetErrorHandler(GuiBldErrorHandler);
fClient->UnregisterWindow(this);
}
////////////////////////////////////////////////////////////////////////////////
/// Destructor
TGuiBldDragManager::~TGuiBldDragManager()
{
SetEditable(kFALSE);
delete fPimpl;
delete fBuilder;
fBuilder = 0;
// delete fEditor;
// fEditor = 0;
delete fFrameMenu;
fFrameMenu =0;
delete fLassoMenu;
fLassoMenu = 0;
if (!gSystem->AccessPathName(fPasteFileName.Data())) {
gSystem->Unlink(fPasteFileName.Data());
}
delete fListOfDialogs;
gGuiBldDragManager = 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Reset some parameters
void TGuiBldDragManager::Reset1()
{
TVirtualDragManager::Init();
fTargetId = 0;
fPimpl->fPlacePopup = kFALSE;
SetCursorType(kPointer);
}
////////////////////////////////////////////////////////////////////////////////
/// Create a list of dialog methods
void TGuiBldDragManager::CreateListOfDialogs()
{
fListOfDialogs = new TList();
TList *methodList = IsA()->GetListOfMethods();
TIter next(methodList);
TString str;
TMethod *method;
while ((method = (TMethod*) next())) {
str = method->GetCommentString();
if (str.Contains("*DIALOG")) {
fListOfDialogs->Add(method);
}
}
}
////////////////////////////////////////////////////////////////////////////////
/// Draw grid on editable frame and restore background on previuosly editted one
void TGuiBldDragManager::Snap2Grid()