Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGuiBldDragManager.cxx
Go to the documentation of this file.
1// @(#)root/guibuilder:$Id: 99541fed972db7e4279fadcd4c0a0f0ae28a0a4d $
2// Author: Valeriy Onuchin 12/09/04
3
4/*************************************************************************
5 * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12
13#include "TGuiBldDragManager.h"
14#include "TGuiBldEditor.h"
15#include "TRootGuiBuilder.h"
16
17#include "TTimer.h"
18#include "TList.h"
19#include "TClass.h"
20#include "TSystem.h"
21#include "TROOT.h"
22#include "TColor.h"
23#include "TImage.h"
24
25#include "TError.h"
26#include "TClassMenuItem.h"
27#include "TMethod.h"
28#include "TMethodCall.h"
29#include "TBaseClass.h"
30#include "TDataMember.h"
31#include "TMethodArg.h"
32#include "TToggle.h"
33#include "TDataType.h"
34#include "TObjString.h"
35#include "TInterpreter.h"
36
37#include "KeySymbols.h"
38#include "TGResourcePool.h"
39#include "TGMenu.h"
40#include "TGFileDialog.h"
41#include "TGMsgBox.h"
42#include "TRandom.h"
43#include "TGButton.h"
44#include "TGMdi.h"
45#include "TGTextEntry.h"
46#include "TGDockableFrame.h"
47#include "TGColorDialog.h"
48#include "TGFontDialog.h"
49#include "TGComboBox.h"
50#include "TGCanvas.h"
51#include "TGLabel.h"
52#include "TGProgressBar.h"
53#include "TGScrollBar.h"
54#include "TVirtualX.h"
55#include "strlcpy.h"
56#include "snprintf.h"
57
58#undef DEBUG_LOCAL
59
60
61/** \class TGuiBldDragManager
62 \ingroup guibuilder
63
64Drag and drop manager used by the ROOT GUI Builder.
65
66*/
67
68
70
71static UInt_t gGridStep = 8;
75
76static const char *gSaveMacroTypes[] = {
77 "Macro files", "*.C",
78 "All files", "*",
79 0, 0
80};
81
82static const char *gImageTypes[] = {
83 "All files", "*",
84 "XPM", "*.xpm",
85 "GIF", "*.gif",
86 "PNG", "*.png",
87 "JPEG", "*.jpg",
88 "TARGA", "*.tga",
89 "BMP", "*.bmp",
90 "ICO", "*.ico",
91 "XCF", "*.xcf",
92 "CURSORS", "*.cur",
93 "PPM", "*.ppm",
94 "PNM", "*.pnm",
95 "XBM", "*.xbm",
96 "TIFF", "*.tiff",
97 "Encapsulated PostScript", "*.eps",
98 "PostScript", "*.ps",
99 "PDF", "*.pdf",
100 "ASImage XML","*.xml",
101 0, 0
102};
103
104
105////////////////////////////////////////////////////////////////////////////////
106
107
109
111
112public:
113 TGButton *fOK; // OK button
114 //TGButton *fApply; // apply button
115 TGButton *fCancel; // cancel button
116 TObject *fObject; // selected object/frame
117 TMethod *fMethod; // method to be applied
118 TGLayoutHints *fL1; // internally used layout hints
119 TGLayoutHints *fL2; // internally used layout hints
120 TList *fWidgets; // list of widgets
121
122public:
123 ~TGuiBldMenuDialog() override;
124 TGuiBldMenuDialog(const TGWindow *main, TObject *obj, TMethod *method);
125
126 const char *GetParameters();
127 void CloseWindow() override;
129 void Build();
130 void Popup();
131 void ApplyMethod();
132 void Add(const char *argname, const char *value, const char *type);
133
134};
135
137
138
139////////////////////////////////////////////////////////////////////////////////
140/// ctor.
141
143 TGTransientFrame(gClient->GetDefaultRoot(), main, 200, 100)
144{
145 fObject = obj;
146 fMethod = method;
147 if (!obj) return; // zombie
148
149 fWidgets = new TList();
150
151 fL1 = new TGLayoutHints(kLHintsTop | kLHintsCenterX, 0, 0, 5, 0);
152 fL2 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
153
154 TString title = obj->ClassName();
155 title += "::";
156 title += method->GetName();
157
158 Build();
160
161 SetWindowName(title);
162 SetIconName(title);
164
165 //TRootGuiBuilder::PropagateBgndColor(this, TRootGuiBuilder::GetBgnd());
166}
167
168////////////////////////////////////////////////////////////////////////////////
169/// dtor.
170
172{
173 fWidgets->Delete();
174 delete fWidgets;
175 delete fL1;
176 delete fL2;
177}
178
179////////////////////////////////////////////////////////////////////////////////
180/// Connect buttons signals
181
183{
184 fOK->Connect("Pressed()", "TGuiBldDragManager", gGuiBldDragManager, "DoDialogOK()");
185 //fApply->Connect("Pressed()", "TGuiBldDragManager", gGuiBldDragManager, "DoDialogApply()");
186 fCancel->Connect("Pressed()", "TGuiBldDragManager", gGuiBldDragManager, "DoDialogCancel()");
187}
188
189////////////////////////////////////////////////////////////////////////////////
190/// execute method for object with input args
191
193{
194 const char *params = GetParameters();
195 fObject->Execute(fMethod->GetName(), params);
196}
197
198////////////////////////////////////////////////////////////////////////////////
199/// Return input parameters as single string.
200
202{
203 static char params[1024];
204 char param[256];
205
206 TObjString *str;
207 TObject *obj;
208
209 Int_t selfobjpos;
210// if (fMenu->GetContextMenu()->GetSelectedMenuItem())
211// selfobjpos = fMenu->GetContextMenu()->GetSelectedMenuItem()->GetSelfObjectPos();
212// else
213 selfobjpos = -1;
214
215 params[0] = 0;
216 TIter next(fWidgets);
217 Int_t nparam = 0;
218
219 while ((obj = next())) { // first element is label, skip...
220 if (obj->IsA() != TGLabel::Class()) break;
221 obj = next(); // get either TGTextEntry or TGComboBox
222 str = (TObjString *) next(); // get type string
223
224 nparam++;
225
226 const char *type = str->GetString().Data();
227 const char *data = 0;
228
229 if (obj->IsA() == TGTextEntry::Class())
230 data = ((TGTextEntry *) obj)->GetBuffer()->GetString();
231
232 // TODO: Combobox...
233
234 // if necessary, replace the selected object by it's address
235 if (selfobjpos == nparam-1) {
236 if (params[0]) strlcat(params, ",", 1024-strlen(params));
237 snprintf(param, 255, "(TObject*)0x%zx", (size_t)fObject);
238 strlcat(params, param, 1024-strlen(params));
239 }
240
241 if (params[0]) strlcat(params, ",", 1024-strlen(params));
242 if (data) {
243 if (!strncmp(type, "char*", 5))
244 snprintf(param, 255, "\"%s\"", data);
245 else
246 strlcpy(param, data, sizeof(param));
247 } else
248 strlcpy(param, "0", sizeof(param));
249
250 strlcat(params, param, 1024-strlen(params));
251 }
252
253 // if selected object is the last argument, have to insert it here
254 if (selfobjpos == nparam) {
255 if (params[0]) strlcat(params, ",", 1024-strlen(params));
256 snprintf(param, 255, "(TObject*)0x%zx", (size_t)fObject);
257 strlcat(params, param, 1024-strlen(params));
258 }
259
260 return params;
261}
262
263////////////////////////////////////////////////////////////////////////////////
264/// Create a string describing method argument.
265
267{
268 static TString ret;
269
270 if (argument) {
271 ret.Form("(%s) %s", argument->GetTitle(), argument->GetName());
272 if (argument->GetDefault() && *(argument->GetDefault())) {
273 ret += " [default: ";
274 ret += argument->GetDefault();
275 ret += "]";
276 }
277 }
278
279 return ret;
280}
281
282////////////////////////////////////////////////////////////////////////////////
283/// Add a label and text input field.
284
285void TGuiBldMenuDialog::Add(const char *argname, const char *value, const char *type)
286{
287 TGLabel *l = new TGLabel(this, argname);
288 TGTextBuffer *b = new TGTextBuffer(20);
289 b->AddText(0, value);
290 TGTextEntry *t = new TGTextEntry(this, b);
291
292 t->Connect("ReturnPressed()", "TGuiBldDragManager", gGuiBldDragManager, "DoDialogOK()");
293 t->Resize(260, t->GetDefaultHeight());
294 AddFrame(l, fL1);
295 AddFrame(t, fL2);
296
297 fWidgets->Add(l);
298 fWidgets->Add(t);
300}
301
302////////////////////////////////////////////////////////////////////////////////
303/// Close window
304
306{
308}
309
310////////////////////////////////////////////////////////////////////////////////
311/// Build dialog
312
314{
315 TMethodArg *argument = 0;
316 Int_t selfobjpos = -1;
317
319 Int_t argpos = 0;
320
321 while ((argument = (TMethodArg *) next())) {
322 // Do not input argument for self object
323 if (selfobjpos != argpos) {
324 TString arg_name = CreateArgumentTitle(argument);
325 const char *argname = arg_name.Data();
326 const char *type = argument->GetTypeName();
327 TDataType *datatype = gROOT->GetType(type);
328 const char *charstar = "char*";
329 char basictype[32];
330
331 if (datatype) {
332 strlcpy(basictype, datatype->GetTypeName(), sizeof(basictype));
333 } else {
335 if (strncmp(type, "enum", 4) && (cl && !(cl->Property() & kIsEnum)))
336 Warning("Dialog", "data type is not basic type, assuming (int)");
337 strlcpy(basictype, "int", sizeof(basictype));
338 }
339
340 if (strchr(argname, '*')) {
341 strlcat(basictype, "*", 32-strlen(basictype));
342 type = charstar;
343 }
344
345 TDataMember *m = argument->GetDataMember();
346 if (m && m->GetterMethod(fObject->IsA())) {
347
348 // Get the current value and form it as a text:
349 char val[256];
350
351 if (!strncmp(basictype, "char*", 5)) {
352 char *tdefval = 0;
353 m->GetterMethod()->Execute(fObject, "", &tdefval);
354 if (tdefval && strlen(tdefval))
355 strlcpy(val, tdefval, sizeof(val));
356 } else if (!strncmp(basictype, "float", 5) ||
357 !strncmp(basictype, "double", 6)) {
358 Double_t ddefval = 0.0;
359 m->GetterMethod()->Execute(fObject, "", ddefval);
360 snprintf(val, 255, "%g", ddefval);
361 } else if (!strncmp(basictype, "char", 4) ||
362 !strncmp(basictype, "bool", 4) ||
363 !strncmp(basictype, "int", 3) ||
364 !strncmp(basictype, "long", 4) ||
365 !strncmp(basictype, "short", 5)) {
366 Longptr_t ldefval = 0L;
367 m->GetterMethod()->Execute(fObject, "", ldefval);
368 snprintf(val, 255, "%zi", (size_t)ldefval);
369 }
370
371 // Find out whether we have options ...
372
373 if (m->GetOptions()) {
374 Warning("Dialog", "option menu not yet implemented");
375 } else {
376 // we haven't got options - textfield ...
377 Add(argname, val, type);
378 }
379 } else { // if m not found ...
380
381 char val[256] = "";
382 const char *tval = argument->GetDefault();
383 if (tval) strlcpy(val, tval, sizeof(val));
384 Add(argname, val, type);
385 }
386 }
387 argpos++;
388 }
389
390 // add OK, Apply, Cancel buttons
391 TGHorizontalFrame *hf = new TGHorizontalFrame(this, 60, 20, kFixedWidth);
393 UInt_t width = 0, height = 0;
394
395 fWidgets->Add(l1);
396
397 fOK = new TGTextButton(hf, "&OK", 1);
398 hf->AddFrame(fOK, l1);
399 fWidgets->Add(fOK);
401
402/*
403 fApply = new TGTextButton(hf, "&Apply", 2);
404 hf->AddFrame(fApply, l1);
405 fWidgets->Add(fApply);
406 height = fApply->GetDefaultHeight();
407 width = TMath::Max(width, fApply->GetDefaultWidth());
408*/
409
410 fCancel = new TGTextButton(hf, "&Cancel", 3);
411 hf->AddFrame(fCancel, l1);
415
416 // place buttons at the bottom
417 l1 = new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5);
418 AddFrame(hf, l1);
419 fWidgets->Add(l1);
420 fWidgets->Add(hf);
421
422 hf->Resize((width + 20) * 3, height);
423
424 // map all widgets and calculate size of dialog
426}
427
428////////////////////////////////////////////////////////////////////////////////
429/// Popup dialog.
430
432{
435
437
438 Window_t wdummy;
439 Int_t x = (Int_t)((TGFrame*)fMain)->GetWidth();
441 gVirtualX->TranslateCoordinates(fMain->GetId(), fClient->GetDefaultRoot()->GetId(),
442 x, y, x, y, wdummy);
443
444 x += 10;
445 y += 10;
446
447 // make the message box non-resizable
450
456
457 Move(x, y);
458 SetWMPosition(x, y);
459 MapRaised();
460 fClient->WaitFor(this);
461}
462
463
464///////////////////////// auxiliary static functions ///////////////////////////
465////////////////////////////////////////////////////////////////////////////////
466/// Helper. Return a window located at point x,y (in screen coordinates)
467
469{
470 Window_t src, dst, child;
471 Window_t ret = 0;
472 Int_t xx = x;
473 Int_t yy = y;
474
476 !gClient->IsEditable()) return 0;
477
478 dst = src = child = gVirtualX->GetDefaultRootWindow();
479
480 while (child && dst) {
481 src = dst;
482 dst = child;
483 gVirtualX->TranslateCoordinates(src, dst, xx, yy, xx, yy, child);
484 ret = dst;
485 }
486 return ret;
487}
488
489////////////////////////////////////////////////////////////////////////////////
490/// Helper to layout
491
492static void layoutFrame(TGFrame *frame)
493{
494 if (!frame || !frame->InheritsFrom(TGCompositeFrame::Class())) {
495 return;
496 }
497
498 TGCompositeFrame *comp = (TGCompositeFrame*)frame;
499
500 if (comp->GetLayoutManager()) {
501 comp->GetLayoutManager()->Layout();
502 } else {
503 comp->Layout();
504 }
505 gClient->NeedRedraw(comp);
506
507 TIter next(comp->GetList());
508 TGFrameElement *fe;
509
510 while ((fe = (TGFrameElement*)next())) {
511 layoutFrame(fe->fFrame);
512 gClient->NeedRedraw(fe->fFrame);
513 }
514}
515
516////////////////////////////////////////////////////////////////////////////////
517/// Our own error handler (not used yet)
518
519static void GuiBldErrorHandler(Int_t /*level*/, Bool_t /*abort*/,
520 const char * /*location*/, const char * /*msg*/)
521{
522}
523
524////////////////////////////////////////////////////////////////////////////////
526
527public:
530 static TGGC *fgBgnd;
531
535
538 void Draw();
539 void SetStep(UInt_t step);
540 void InitPixmap();
541 void InitBgnd();
542};
543
547
548////////////////////////////////////////////////////////////////////////////////
549/// Create a grid background for the selected window
550
552{
553 fPixmap = 0;
554 fWindow = 0;
555 fWinId = 0;
556
557 if (!fgBgnd) {
558 InitBgnd();
559 }
561}
562
563////////////////////////////////////////////////////////////////////////////////
564/// ctor.
565
567{
568 fWindow = gClient->GetWindowById(fWinId);
569
570 if (fWindow) {
572 fWindow->SetBackgroundColor(((TGFrame*)fWindow)->GetBackground());
573 gClient->NeedRedraw(fWindow, kTRUE);
574 }
575 if (fPixmap) {
576 gVirtualX->DeletePixmap(fPixmap);
577 }
578
579 fPixmap = 0;
580 fWindow = 0;
581 fWinId = 0;
582}
583
584////////////////////////////////////////////////////////////////////////////////
585/// Set the grid step
586
588{
589 if (!gClient || !gClient->IsEditable()) {
590 return;
591 }
592
593 fWindow = (TGWindow*)gClient->GetRoot();
594 fWinId = fWindow->GetId();
595 fgStep = step;
596 InitPixmap();
597
598}
599
600////////////////////////////////////////////////////////////////////////////////
601/// Create grid background.
602
604{
605 if (fgBgnd) {
606 return;
607 }
608
610
611 Float_t r, g, b;
612
613 r = 232./255;
614 g = 232./255;
615 b = 226./255;
616
619}
620
621////////////////////////////////////////////////////////////////////////////////
622/// Create grid background pixmap
623
625{
626 if (fPixmap) {
627 gVirtualX->DeletePixmap(fPixmap);
628 }
629
630 fPixmap = gVirtualX->CreatePixmap(gClient->GetDefaultRoot()->GetId(), fgStep, fgStep);
631 gVirtualX->FillRectangle(fPixmap, fgBgnd->GetGC(), 0, 0, fgStep, fgStep);
632
633 if(fgStep > 2) {
634 gVirtualX->FillRectangle(fPixmap, TGFrame::GetShadowGC()(),
635 fgStep - 1, fgStep - 1, 1, 1);
636 }
637}
638
639////////////////////////////////////////////////////////////////////////////////
640/// Draw grid over edited frame.
641
643{
644 if (!gClient || !gClient->IsEditable()) {
645 return;
646 }
647
648 fWindow = gClient->GetWindowById(fWinId);
649
650 if (fWindow && (fWindow != gClient->GetRoot())) {
652 fWindow->SetBackgroundColor(((TGFrame*)fWindow)->GetBackground());
653 gClient->NeedRedraw(fWindow);
654 }
655
656 if (!fPixmap) {
657 InitPixmap();
658 }
659
660 fWindow = (TGWindow*)gClient->GetRoot();
661 fWinId = fWindow->GetId();
663
664 gClient->NeedRedraw(fWindow);
665}
666
667
668////////////////////////////////////////////////////////////////////////////////
670
671private:
672 TGuiBldDragManager *fManager; // back pointer
673
674public:
676 TTimer(ms, kTRUE) { fManager = m; }
677 Bool_t Notify() override { fManager->HandleTimer(this); Reset(); return kFALSE; }
678};
679
680
681////////////////////////////////////////////////////////////////////////////////
682class TGGrabRect : public TGFrame {
683
684private:
687
688public:
690 ~TGGrabRect() override {}
691
692 Bool_t HandleButton(Event_t *ev) override;
693 ECursor GetType() const { return fType; }
694};
695
696////////////////////////////////////////////////////////////////////////////////
697/// ctor.
698
700 TGFrame(gClient->GetDefaultRoot(), 8, 8, kTempFrame)
701{
702 fType = kTopLeft;
703
704 switch (type) {
705 case 0:
706 fType = kTopLeft;
707 break;
708 case 1:
709 fType = kTopSide;
710 break;
711 case 2:
713 break;
714 case 3:
716 break;
717 case 4:
719 break;
720 case 5:
722 break;
723 case 6:
725 break;
726 case 7:
728 break;
729 }
730
733 attr.fOverrideRedirect = kTRUE;
734 attr.fSaveUnder = kTRUE;
735
736 gVirtualX->ChangeWindowAttributes(fId, &attr);
737
738 fPixmap = gVirtualX->CreatePixmap(gVirtualX->GetDefaultRootWindow(), 8, 8);
740//fClient->GetResourcePool()->GetSelectedBckgndGC();
742
743 Pixel_t back;
744 fClient->GetColorByName("black", back);
745 gc->SetBackground(back);
746 gc->SetForeground(back);
747
748 gVirtualX->FillRectangle(fPixmap, bgc->GetGC(), 0, 0, 7, 7);
749 gVirtualX->DrawRectangle(fPixmap, gc->GetGC(), 0, 0, 7, 7);
750// gVirtualX->DrawRectangle(fPixmap, fClient->GetResourcePool()->GetSelectedBckgndGC()->GetGC(), 1, 1, 5, 5);
751
754
755 gVirtualX->SetCursor(fId, gVirtualX->CreateCursor(fType));
756}
757
758////////////////////////////////////////////////////////////////////////////////
759/// Handle button press event.
760
762{
764 return kTRUE;
765}
766
767////////////////////////////////////////////////////////////////////////////////
768class TGAroundFrame : public TGFrame {
769
770public:
772 ~TGAroundFrame() override {}
773};
774
775////////////////////////////////////////////////////////////////////////////////
776/// ctor.
777
778TGAroundFrame::TGAroundFrame() : TGFrame(gClient->GetDefaultRoot(), 1, 1,
780{
783 attr.fOverrideRedirect = kTRUE;
784 attr.fSaveUnder = kTRUE;
785
786 gVirtualX->ChangeWindowAttributes(fId, &attr);
787 ULong_t blue;
788 fClient->GetColorByName("blue", blue);
789 SetBackgroundColor(blue);
790}
791
792
793////////////////////////////////////////////////////////////////////////////////
795
797
798private:
799 TGuiBldDragManager *fManager; // drag and drop manager
800 TTimer *fRepeatTimer; // repeat rate timer (when mouse stays pressed)
801 TGFrame *fGrab; // grabbed/selected frame
802 TGLayoutHints *fGrabLayout; // layout of grabbed frame
803 TGFrame *fSaveGrab; // used during context menu handling
804 TGFrame *fClickFrame; // last clicked frame
806 ECursor fResizeType; // defines resize type
807 Int_t fX0, fY0; // initial drag position in pixels
808 Int_t fX, fY; // current drag position in pixels
809 Int_t fXf, fYf; // offset of initial position inside frame
811 const TGWindow *fGrabParent; // parent of the grabbed/selected frame
814 TGGrabRect *fGrabRect[8]; // small rectangles drawn over grabbed/selected frame
815 TGFrame *fAroundFrame[4]; // red lines drawn over laid out frame
820 TGFrame *fPlane; // highlighted plain composite frame when mose is moving
821 TGFrame *fSpacePressedFrame; // frame which was grabbed via spacebar pressed
822 Bool_t fPlacePopup; // kTRUE is menu fo frame was placed
823 TList *fFrameMenuTrash; // trash list
824 TGFrame *fMenuObject; // object/frame for which context menu is created
825
826public:
828 fManager = m;
830
831 int i = 0;
832 for (i = 0; i <8; i++) {
833 fGrabRect[i] = new TGGrabRect(i);
834 }
835 for (i = 0; i <4; i++) {
836 fAroundFrame[i] = new TGAroundFrame();
837 }
838
839 fFrameMenuTrash = new TList();
840
841 ResetParams();
842 }
843 void ResetParams() {
844 fGrab = 0;
845 fSaveGrab = 0;
846 fClickFrame = 0;
847 fGrid = 0;
848 fX0 = fY0 = fX = fY = fXf = fYf = fGrabX = fGrabY = 0;
849 fGrabParent = 0;
853 fGrabLayout = 0;
858 fPlane = 0;
862 fMenuObject = 0;
863 }
864
866 int i;
867 for (i = 0; i <8; i++) {
868 delete fGrabRect[i];
869 }
870 for (i = 0; i <4; i++) {
871 delete fAroundFrame[i];
872 }
873
874 delete fRepeatTimer;
875 delete fGrab;
877 delete fFrameMenuTrash;
878
879 if (fPlane) {
881 gClient->NeedRedraw(fPlane, kTRUE);
882 fPlane = 0;
883 }
884 }
885};
886
887
888////////////////////////////////////////////////////////////////////////////////
890 TGFrame(gClient->GetDefaultRoot(), 1, 1)
891{
892 // Constructor. Create "fantom window".
893
896 attr.fOverrideRedirect = kTRUE;
897 attr.fSaveUnder = kTRUE;
898
899 gVirtualX->ChangeWindowAttributes(fId, &attr);
900
901 gGuiBldDragManager = this;
903
905 fFrameMenu = 0;
906 fLassoMenu = 0;
907 fEditor = 0;
908 fBuilder = 0;
911 fStop = kTRUE;
912 fSelected = 0;
913 fListOfDialogs = 0;
914
915 Reset1();
917
918 TString tmpfile = gSystem->TempDirectory();
919 char *s = gSystem->ConcatFileName(tmpfile.Data(),
920 TString::Format("RootGuiBldClipboard%d.C", gSystem->GetPid()));
921 fPasteFileName = s;
922 delete [] s;
923
924 s = gSystem->ConcatFileName(tmpfile.Data(),
925 TString::Format("RootGuiBldTmpFile%d.C", gSystem->GetPid()));
926 fTmpBuildFile = s;
927 delete [] s;
928
929 fName = "Gui Builder Drag Manager";
931
932 // let's try to solve the problems by myself
934
936}
937
938////////////////////////////////////////////////////////////////////////////////
939/// Destructor
940
942{
944
945 delete fPimpl;
946
947 delete fBuilder;
948 fBuilder = 0;
949
950// delete fEditor;
951// fEditor = 0;
952
953 delete fFrameMenu;
954 fFrameMenu =0;
955
956 delete fLassoMenu;
957 fLassoMenu = 0;
958
961 }
962
963 delete fListOfDialogs;
964
966}
967
968////////////////////////////////////////////////////////////////////////////////
969/// Reset some parameters
970
972{
974 fTargetId = 0;
977}
978
979////////////////////////////////////////////////////////////////////////////////
980/// Create a list of dialog methods
981
983{
984 fListOfDialogs = new TList();
985
986 TList *methodList = IsA()->GetListOfMethods();
987 TIter next(methodList);
988 TString str;
989 TMethod *method;
990
991 while ((method = (TMethod*) next())) {
992 str = method->GetCommentString();
993 if (str.Contains("*DIALOG")) {
994 fListOfDialogs->Add(method);
995 }
996 }
997}
998
999////////////////////////////////////////////////////////////////////////////////
1000/// Draw grid on editable frame and restore background on previously edited one
1001
1003{
1004 if (fStop) {
1005 return;
1006 }
1007
1008 delete fPimpl->fGrid;
1009
1011 fPimpl->fGrid->Draw();
1012}
1013
1014////////////////////////////////////////////////////////////////////////////////
1015/// Return the grid step
1016
1018{
1019 return fPimpl->fGrid ? fPimpl->fGrid->fgStep : 1;
1020}
1021
1022////////////////////////////////////////////////////////////////////////////////
1023/// Set the grid step
1024
1026{
1027 fPimpl->fGrid->SetStep(step);
1028}
1029
1030////////////////////////////////////////////////////////////////////////////////
1031/// Return kTRUE if event is rejected for processing by drag manager
1032
1034{
1035 if (fStop || !fClient || !fClient->IsEditable()) return kTRUE;
1036 if (event->fType == kClientMessage) return kFALSE;
1037 if (event->fType == kDestroyNotify) return kFALSE;
1038
1039 TGWindow *w = fClient->GetWindowById(event->fWindow);
1040
1041 if (w) {
1042 if (IsEditDisabled(w)) {
1044 return !w;
1045 }
1046 } else {
1047 return kTRUE;
1048 }
1049 return kFALSE;
1050}
1051
1052////////////////////////////////////////////////////////////////////////////////
1053/// Return a pointer to the parent window (which is being edited)
1054
1056{
1057 if (fStop || !id) {
1058 return 0;
1059 }
1060
1061 Window_t preparent = id;
1062 Window_t parent = (Window_t)gVirtualX->GetParent(id);
1063
1064 while (!parent || (parent != fClient->GetDefaultRoot()->GetId())) {
1065 if (parent == fClient->GetRoot()->GetId()) {
1066 TGWindow *w = fClient->GetWindowById(preparent);
1067 return (w ? (TGFrame*)w : 0);
1068 }
1069 preparent = parent;
1070 parent = gVirtualX->GetParent(parent);
1071 }
1072 return 0;
1073}
1074
1075////////////////////////////////////////////////////////////////////////////////
1076/// Find the first composite parent of window
1077
1079{
1080 if (fStop || !id) {
1081 return 0;
1082 }
1083
1084 Window_t parent = id;
1085
1086 while (!parent || (parent != fClient->GetDefaultRoot()->GetId())) {
1087 TGWindow *w = fClient->GetWindowById(parent);
1088 if (w) {
1089 if (w->InheritsFrom(TGCompositeFrame::Class())) {
1090 return (TGCompositeFrame*)w;
1091 }
1092 }
1093 parent = gVirtualX->GetParent(parent);
1094 }
1095 return 0;
1096}
1097
1098////////////////////////////////////////////////////////////////////////////////
1099/// Set cursor for selected/grabbed frame.
1100
1102{
1103 if (fStop) {
1104 return;
1105 }
1106
1107 static UInt_t gid = 0;
1108 static UInt_t rid = 0;
1109
1110 if (fPimpl->fGrab && (gid != fPimpl->fGrab->GetId())) {
1111 gVirtualX->SetCursor(fPimpl->fGrab->GetId(),
1112 gVirtualX->CreateCursor((ECursor)cur));
1113 gid = fPimpl->fGrab->GetId();
1114 }
1115 if (fClient->IsEditable() && (rid != fClient->GetRoot()->GetId())) {
1116 gVirtualX->SetCursor(fClient->GetRoot()->GetId(),
1117 gVirtualX->CreateCursor((ECursor)cur));
1118 rid = fClient->GetRoot()->GetId();
1119 }
1120}
1121
1122////////////////////////////////////////////////////////////////////////////////
1123/// Check resize type event.
1124
1126{
1127 if (fStop) {
1128 return kFALSE;
1129 }
1130
1131 Bool_t ret = kFALSE;
1133
1134 for (int i = 0; i < 8; i++) {
1135 if (fPimpl->fGrabRect[i]->GetId() == event->fWindow) {
1137 ret = kTRUE;
1138 }
1139 }
1140
1141 if ((event->fType == kButtonPress) && (fPimpl->fResizeType != kPointer)) {
1143 ret = kTRUE;
1144 }
1145
1147 return ret;
1148}
1149
1150////////////////////////////////////////////////////////////////////////////////
1151/// Redraw the edited window
1152
1154{
1155 if (fStop || !fClient || !fClient->IsEditable()) {
1156 return;
1157 }
1158
1159 TGWindow *root = (TGWindow*)fClient->GetRoot();
1160
1161 fClient->NeedRedraw(root, kTRUE);
1162
1163 if (fBuilder) {
1165 }
1166}
1167
1168////////////////////////////////////////////////////////////////////////////////
1169/// Switch editable
1170
1172{
1173 if (fStop || !frame) {
1174 return;
1175 }
1176
1177 TGCompositeFrame *comp = 0;
1178
1179 if (frame->InheritsFrom(TGCompositeFrame::Class()) && CanChangeLayout(frame)) {
1180 comp = (TGCompositeFrame *)frame;
1181 } else if (frame->GetParent()->InheritsFrom(TGCompositeFrame::Class())) {
1182 comp = (TGCompositeFrame *)frame->GetParent();
1183 }
1184
1185 if (!comp) {
1186 return;
1187 }
1188
1189 TString str = comp->ClassName();
1190 str += "::";
1191 str += comp->GetName();
1192
1193 if (IsEditDisabled(comp)) {
1194 if (fBuilder) {
1195 str += " cannot be edited.";
1197 }
1198 return;
1199 }
1200
1201 if (frame != comp) {
1202 SelectFrame(frame);
1203 }
1204
1205 if (comp->IsEditable()) {
1206 return;
1207 }
1208
1209 RaiseMdiFrame(comp);
1210 comp->SetEditable(kTRUE);
1211}
1212
1213////////////////////////////////////////////////////////////////////////////////
1214/// Grab/Select frame
1215
1217{
1218 if (fStop || !frame || (frame->GetParent() == fClient->GetDefaultRoot()) ||
1219 !fClient->IsEditable()) {
1220 return;
1221 }
1222
1223 TString str = frame->ClassName();
1224 str += "::";
1225 str += frame->GetName();
1226
1227 if (IsGrabDisabled(frame)) {
1228 if (fBuilder) {
1229 str += "can not be selected";
1231 }
1232 return;
1233 }
1234
1235 // do not grab mdi frames (quick hack)
1236 if (fBuilder && frame->InheritsFrom(TGMdiFrame::Class())) {
1237 return;
1238 }
1239
1240
1241 static Int_t x, x0, y, y0, xx, yy;
1242 Window_t c;
1243
1245 frame->MapRaised();
1246
1247 if (!add) {
1248
1250
1251 gVirtualX->TranslateCoordinates(frame->GetId(),
1253 0, 0, x0, y0, c);
1254
1255 x = x0 + frame->GetWidth();
1256 y = y0 + frame->GetHeight();
1257
1258 if (fBuilder) {
1259 str += " selected";
1260 str += (IsEditDisabled(frame) || IsFixedLayout(frame) ? ". This frame cannot be edited." :
1261 " ");
1262 str += " Press SpaceBar to unselect the frame.";
1263 if (IsFixedSize(frame)) str += " This frame cannot be resized.";
1264
1266 }
1267
1268 } else { //shift mask is on
1269
1270 gVirtualX->TranslateCoordinates(frame->GetId(),
1272 0, 0, xx, yy, c);
1273
1275 fPimpl->fX0 = x0 = TMath::Min(x0, xx);
1276 fPimpl->fX = x = TMath::Max(x, xx + (Int_t)frame->GetWidth());
1277 fPimpl->fY0 = y0 = TMath::Min(y0, yy);
1278 fPimpl->fY = y = TMath::Max(y, yy + (Int_t)frame->GetHeight());
1279
1280 DrawLasso();
1281 }
1282
1283 fFrameUnder = fPimpl->fGrab = frame;
1285
1286 // quick hack. the special case for TGCanvases
1287 if (frame->InheritsFrom(TGCanvas::Class())) {
1288 fSelected = ((TGCanvas*)frame)->GetContainer();
1289
1290 if (!IsEditDisabled(fSelected)) {
1292 if (fBuilder && fBuilder->GetAction()) {
1294 }
1295 }
1296 } else {
1298 }
1300
1302
1305}
1306
1307////////////////////////////////////////////////////////////////////////////////
1308/// Inform outside wold that selected frame was changed
1309
1311{
1312 if (fStop) {
1313 return;
1314 }
1315
1316 TGFrame *sel = fr;
1317
1318 if (fBuilder && (sel == fBuilder->GetMdiMain()->GetCurrent())) {
1319 sel = 0;
1320 }
1321
1322 if (!fr) {
1323 UngrabFrame();
1324 }
1325
1326 if (fEditor) {
1328 }
1329
1330 if (fBuilder) {
1332 //fBuilder->Update();
1333 }
1334}
1335
1336////////////////////////////////////////////////////////////////////////////////
1337/// grab frame (see SelectFrame)
1338
1340{
1341 if (fStop || !frame || !fClient->IsEditable()) {
1342 return;
1343 }
1344
1345 fPimpl->fGrabParent = frame->GetParent();
1346 fPimpl->fGrabX = frame->GetX();
1347 fPimpl->fGrabY = frame->GetY();
1348
1349 Window_t c;
1350
1351 gVirtualX->TranslateCoordinates(frame->GetId(),
1353 0, 0, fPimpl->fX0, fPimpl->fY0, c);
1354
1355 fPimpl->fX = fPimpl->fX0;
1356 fPimpl->fY = fPimpl->fY0;
1357
1358 if (frame->GetFrameElement() && frame->GetFrameElement()->fLayout) {
1360 }
1361
1362 if (fPimpl->fGrabParent && frame->GetFrameElement() &&
1364 TList *li = ((TGCompositeFrame*)fPimpl->fGrabParent)->GetList();
1366 ((TGCompositeFrame*)fPimpl->fGrabParent)->RemoveFrame(frame);
1367 }
1368
1371 attr.fOverrideRedirect = kTRUE;
1372 attr.fSaveUnder = kTRUE;
1373
1374 gVirtualX->ChangeWindowAttributes(frame->GetId(), &attr);
1375
1376 frame->UnmapWindow();
1378 gVirtualX->Update(1);
1379 frame->Move(fPimpl->fX0, fPimpl->fY0);
1380 frame->MapRaised();
1381
1382 if (fBuilder) {
1383 //fBuilder->Update();
1384 TString str = frame->ClassName();
1385 str += "::";
1386 str += frame->GetName();
1387 str += " is grabbed";
1388
1390 }
1391}
1392
1393////////////////////////////////////////////////////////////////////////////////
1394/// Ungrab/Unselect selected/grabbed frame.
1395
1397{
1398 if (fStop || !fPimpl->fGrab) {
1399 return;
1400 }
1401
1404
1405 DoRedraw();
1406
1407 if (fBuilder) {
1408 //fBuilder->Update();
1409 TString str = fPimpl->fGrab->ClassName();
1410 str += "::";
1411 str += fPimpl->fGrab->GetName();
1412 str += " ungrabbed";
1414 }
1415 fSelected = fPimpl->fGrab = 0;
1416}
1417
1418////////////////////////////////////////////////////////////////////////////////
1419/// Helper for IsPointVisible
1420
1422{
1423 const TGWindow *parent = grab;
1424
1425 while (parent && (parent != gClient->GetDefaultRoot())) {
1426 if (parent->GetId() == id) {
1427 return kTRUE;
1428 }
1429 parent = parent->GetParent();
1430 }
1431
1432 return kFALSE;
1433}
1434
1435////////////////////////////////////////////////////////////////////////////////
1436/// Helper function for IsSelectedWindow method
1437
1439{
1440 Window_t w = gVirtualX->GetDefaultRootWindow();
1441 Window_t src, dst, child;
1442 Int_t x = xi;
1443 Int_t y = yi;
1444 Bool_t ret = kFALSE;
1445
1446 gVirtualX->TranslateCoordinates(fPimpl->fGrab->GetId(), w, x, y, x, y, child);
1447
1448 dst = src = child = w;
1449
1450 while (child) {
1451 src = dst;
1452 dst = child;
1453 gVirtualX->TranslateCoordinates(src, dst, x, y, x, y, child);
1454
1456 return kTRUE;
1457 }
1458 }
1459
1460 return ret;
1461}
1462
1463////////////////////////////////////////////////////////////////////////////////
1464/// Return kTRUE if grabbed/selected frame is not overlapped by other windows.
1465
1467{
1468 if (fStop || !fPimpl->fGrab || !fClient->IsEditable()) {
1469 return kFALSE;
1470 }
1471
1472 if (fBuilder) {
1474 if (mdi && (mdi != fBuilder->GetMdiMain()->GetCurrent())) {
1475 return kFALSE;
1476 }
1477 }
1478
1479 // popup menu was placed
1480 if (fPimpl->fPlacePopup) {
1481 return kTRUE;
1482 }
1483
1484 static Long64_t was = gSystem->Now();
1485 static Bool_t visible = kFALSE;
1486
1487 Long64_t now = gSystem->Now();
1488
1489 if (now-was < 100) {
1490 return visible;
1491 }
1492 was = now;
1493
1494 visible = kFALSE;
1495
1496 if (!IsPointVisible(2, 2)) {
1497 return visible;
1498 }
1499
1500 if (!IsPointVisible(2, fPimpl->fGrab->GetHeight()-2)) {
1501 return visible;
1502 }
1503
1504 if (!IsPointVisible(fPimpl->fGrab->GetWidth()-2, 2)) {
1505 return visible;
1506 }
1507
1509 fPimpl->fGrab->GetHeight()-2)) {
1510 return visible;
1511 }
1512
1513 visible = kTRUE;
1514
1515 return visible;
1516}
1517
1518////////////////////////////////////////////////////////////////////////////////
1519/// Draw small grab rectangles around grabbed/selected/frame
1520
1522{
1523 if (fStop) {
1524 return;
1525 }
1526
1527 TGFrame *frame = win ? (TGFrame *)win : fPimpl->fGrab;
1528
1529 if (!frame || !fClient->IsEditable() || fPimpl->fPlacePopup) {
1530 return;
1531 }
1532
1533 Window_t w = gVirtualX->GetDefaultRootWindow();
1534 Window_t c; Int_t x, y;
1535
1536 gVirtualX->TranslateCoordinates(frame->GetId(), w, 0, 0, x, y, c);
1537
1538 if (frame->InheritsFrom(TGCompositeFrame::Class()) &&
1539 CanChangeLayout(frame) && !frame->IsLayoutBroken()) {
1540 fPimpl->fAroundFrame[0]->MoveResize(x-3, y-3, frame->GetWidth()+6, 2);
1542 fPimpl->fAroundFrame[1]->MoveResize(x+frame->GetWidth()+3, y-3, 2, frame->GetHeight()+6);
1544 fPimpl->fAroundFrame[2]->MoveResize(x-3, y+frame->GetHeight()+2, frame->GetWidth()+6, 2);
1546 fPimpl->fAroundFrame[3]->MoveResize(x-3, y-3, 2, frame->GetHeight()+6);
1548 } else {
1549 for (int i = 0; i < 4; i++) fPimpl->fAroundFrame[i]->UnmapWindow();
1550 }
1551
1552 // draw rectangles
1553 DrawGrabRect(0, x - 6, y - 6);
1554 DrawGrabRect(1, x + frame->GetWidth()/2 - 3, y - 6);
1555 DrawGrabRect(2, x + frame->GetWidth(), y - 6);
1556 DrawGrabRect(3, x - 6, y + frame->GetHeight());
1557 DrawGrabRect(4, x - 6, y + frame->GetHeight()/2 - 3);
1558 DrawGrabRect(5, x + frame->GetWidth(), y + frame->GetHeight()/2 - 3);
1559 DrawGrabRect(6, x + frame->GetWidth()/2 - 3, y + frame->GetHeight());
1560 DrawGrabRect(7, x + frame->GetWidth(), y + frame->GetHeight());
1561
1563}
1564
1565////////////////////////////////////////////////////////////////////////////////
1566/// Helper method to draw grab rectangle at position x,y
1567
1569{
1570 if (fStop) {
1571 return;
1572 }
1573
1574 fPimpl->fGrabRect[i]->Move(x, y);
1575 fPimpl->fGrabRect[i]->MapRaised();
1576}
1577
1578////////////////////////////////////////////////////////////////////////////////
1579/// Raise composite frame when mouse is moving over it.
1580/// That allows to highlight position of "plain" composite frames.
1581
1583{
1584 static Window_t gw = 0;
1585
1586 if (fStop || !win || (win == gw)) {
1587 return;
1588 }
1589
1591
1592 if (!w || (w == fPimpl->fPlane) || w->GetEditDisabled() || w->IsEditable() ||
1593 !w->InheritsFrom(TGCompositeFrame::Class())) {
1594 return;
1595 }
1596
1597 TGFrame *frame = (TGFrame*)w;
1598 UInt_t opt = frame->GetOptions();
1599
1600 if ((opt & kRaisedFrame) || (opt & kSunkenFrame)) {
1601 return;
1602 }
1603
1604 gw = win;
1605 if (fPimpl->fPlane) {
1606 fPimpl->fPlane->ChangeOptions(fPimpl->fPlane->GetOptions() & ~kRaisedFrame);
1608 }
1609 fPimpl->fPlane = frame;
1612
1613 if (fBuilder) {
1614 TString str = frame->ClassName();
1615 str += "::";
1616 str += frame->GetName();
1618 }
1619}
1620
1621////////////////////////////////////////////////////////////////////////////////
1622/// The main event loop is originated here
1623/// It repeatedly queries pointer state and position on the screen.
1624/// From this info an Event_t structure is built.
1625
1627{
1628 return HandleTimerEvent(0, t);
1629}
1630
1631////////////////////////////////////////////////////////////////////////////////
1632/// Handle timer events or events coming from the recorder.
1633
1635{
1636 static Int_t gy = 0;
1637 static Int_t gx = 0;
1638 static UInt_t gstate = 0;
1639 static Window_t gw = 0;
1640
1641 Bool_t ret = kTRUE;
1642
1643 // if nothing is edited stop timer and reset everything
1644 if (!fClient || !fClient->IsEditable()) {
1646 return kFALSE;
1647 }
1648 if (!IsSelectedVisible()) {
1650 }
1651 if (e) {
1652 if (fPimpl->fRepeatTimer) {
1653 // we are replaying events from the recorder...
1656 }
1657 if (e->fType == kButtonPress)
1658 return HandleButtonPress(e);
1659 else if (e->fType == kButtonRelease)
1660 return HandleButtonRelease(e);
1661 else if (e->fState & kButton1Mask)
1662 return HandleMotion(e);
1663 return kTRUE;
1664 }
1665 Window_t dum;
1666 Event_t ev;
1667 ev.fCode = kButton1;
1668 ev.fType = kMotionNotify;
1669 ev.fState = 0;
1670
1671 gVirtualX->QueryPointer(gVirtualX->GetDefaultRootWindow(), dum, dum,
1672 ev.fXRoot, ev.fYRoot, ev.fX, ev.fY, ev.fState);
1673
1675
1676 if (ev.fWindow && (gw == ev.fWindow) && (gstate == ev.fState) &&
1677 (ev.fYRoot == gy) && (ev.fXRoot == gx)) {
1678 return kFALSE;
1679 }
1680
1681 gw = ev.fWindow;
1682 gstate = ev.fState;
1683 ev.fState &= ~16; // ignore "num lock" pressed
1684 ev.fState &= ~2; // ignore "caps lock" pressed
1685
1687 ((ev.fState == kButton1Mask) || (ev.fState == kButton3Mask) ||
1688 (ev.fState == (kButton1Mask | kKeyShiftMask)) ||
1689 (ev.fState == (kButton1Mask | kKeyControlMask)))) {
1690
1691 if (ev.fState & kButton1Mask) ev.fCode = kButton1;
1692 if (ev.fState & kButton3Mask) ev.fCode = kButton3;
1693
1694 ev.fType = kButtonPress;
1695 t->SetTime(40);
1696
1700 } else {
1701 fPimpl->fPlane = 0;
1702 }
1703
1704 ret = HandleButtonPress(&ev);
1705 TimerEvent(&ev);
1706 return ret;
1707 }
1708
1709 if ((fDragging || fMoveWaiting) && (!ev.fState || (ev.fState == kKeyShiftMask)) &&
1711
1712 ev.fType = kButtonRelease;
1713 t->SetTime(100);
1714
1715 ret = HandleButtonRelease(&ev);
1716 TimerEvent(&ev);
1717 return ret;
1718 }
1719
1721 (ev.fState & kButton2Mask) ||
1722 (ev.fState & kButton3Mask);
1723
1724 if ((ev.fYRoot == gy) && (ev.fXRoot == gx)) return kFALSE;
1725
1726 gy = ev.fYRoot;
1727 gx = ev.fXRoot;
1728
1729 if (!fMoveWaiting && !fDragging && !ev.fState) {
1730 if (!CheckDragResize(&ev) && fClient->GetWindowById(ev.fWindow)) {
1732 }
1733 } else if (ev.fState & kButton1Mask) {
1734 HandleMotion(&ev);
1735 TimerEvent(&ev);
1736 }
1737 return ret;
1738}
1739
1740////////////////////////////////////////////////////////////////////////////////
1741/// Recognize what was done when mouse button pressed
1742
1744{
1745 if (fStop) {
1746 return kFALSE;
1747 }
1748
1749 if (((event->fCode != kButton1) && (event->fCode != kButton3)) ||
1750 !frame || !fClient->IsEditable()) {
1751 return kFALSE;
1752 }
1753
1754 TGFrame *context_fr = 0;
1755 Bool_t mdi = kFALSE;
1756
1757 // hack for editable mdi frames
1758 if (frame->IsEditable() && frame->InheritsFrom(TGMdiFrame::Class())) {
1759 context_fr = frame;
1760 mdi = kTRUE;
1761 }
1762
1763 // handle context menu
1764 if (event->fCode == kButton3) {
1765 if (!fPimpl->fSpacePressedFrame) {
1766 if (!mdi) {
1767 SelectFrame(frame);
1768 context_fr = fSelected;
1769 }
1770 } else {
1771 context_fr = fPimpl->fSpacePressedFrame;
1772 }
1773
1774 HandleButon3Pressed(event, context_fr);
1775 return kTRUE;
1776 }
1777
1779
1780 if (!fSelectionIsOn) {
1781 fPimpl->fX0 = event->fXRoot;
1782 fPimpl->fY0 = event->fYRoot;
1783 }
1784
1785 //HideGrabRectangles();
1786 fPimpl->fClickFrame = frame;
1787
1788 if (fBuilder && fBuilder->IsExecutable() &&
1790 UngrabFrame();
1791 frame->SetEditable(kTRUE);
1792 fSource = 0;
1794 goto out;
1795 }
1796
1797 if (event->fState & kKeyShiftMask) {
1798 // drag grabbed frame with shift key pressed should create a copy of grabbed frame
1799 // move a copy of editable and selected frame
1800 if (frame == fPimpl->fGrab) {
1801 fSource = frame;
1803 gVirtualX->SetCursor(frame->GetId(), gVirtualX->CreateCursor(kMove));
1804 goto out;
1805 }
1806
1807 // otherwise do lasso selection
1808 if (!fSelectionIsOn) {
1810 } else {
1811 fPimpl->fX = event->fXRoot;
1812 fPimpl->fY = event->fYRoot;
1814 DrawLasso();
1815 return kTRUE;
1816 }
1817 }
1818
1820
1821 if (frame->IsEditable()) {
1822 fSource = 0;
1823
1824 if (fDragType != kDragResize) {
1825
1826 // move editable and selected frame
1827 if (frame == fPimpl->fGrab) {
1828 fSource = frame;
1830 gVirtualX->SetCursor(frame->GetId(), gVirtualX->CreateCursor(kMove));
1831 goto out;
1832 }
1833
1835 }
1836 } else if ((fDragType != kDragResize) && !fPimpl->fSpacePressedFrame) {
1837
1838 // special case of TGCanvas
1839 if (!fPimpl->fGrab && frame->InheritsFrom(TGCanvas::Class())) {
1840 TGFrame *cont = ((TGCanvas*)frame)->GetContainer();
1841
1842 if (!cont->IsEditable()) {
1843 cont->SetEditable(kTRUE);
1845 goto out;
1846 }
1847 }
1848
1849 fSource = frame;
1850 SelectFrame(frame, event->fState & kKeyShiftMask);
1851 }
1852
1854 SwitchEditable(frame);
1855 fSource = 0;
1856
1857 // try again
1859
1860 if (fDragType == kDragNone) {
1861 return kFALSE;
1862 }
1863 }
1864
1865out:
1866 Window_t c;
1867
1868 gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(),
1869 frame->GetId(),
1870 event->fXRoot, event->fYRoot,
1871 fPimpl->fXf, fPimpl->fYf, c);
1872 fPimpl->fX = event->fXRoot;
1873 fPimpl->fY = event->fYRoot;
1874
1876 DoRedraw();
1877
1878 return kTRUE;
1879}
1880
1881////////////////////////////////////////////////////////////////////////////////
1882/// Handle 3d mouse pressed (popup context menu)
1883
1885{
1886 if (fStop || !frame) {
1887 return;
1888 }
1889
1891 return;
1892 }
1893
1894 if (frame == fSelected) {
1895 Menu4Frame(frame, event->fXRoot, event->fYRoot);
1896 } else if (frame->IsEditable()) {
1897 if (fLassoDrawn) {
1898 Menu4Lasso(event->fXRoot, event->fYRoot);
1899 } else {
1900 Menu4Frame(frame, event->fXRoot, event->fYRoot);
1901 }
1902 } else {
1903 TGFrame *base = InEditable(frame->GetId());
1904 if (base) {
1905 //SelectFrame(base);
1906 Menu4Frame(base, event->fXRoot, event->fYRoot);
1907 } else {
1908 Menu4Frame(frame, event->fXRoot, event->fYRoot);
1909 }
1910 }
1911}
1912
1913////////////////////////////////////////////////////////////////////////////////
1914/// Handle button event occurred in some ROOT frame
1915
1917{
1918 if (fStop) {
1919 return kFALSE;
1920 }
1921
1922 if (event->fCode != kButton3) {
1923 CloseMenus();
1924 }
1925
1926 if (event->fType == kButtonPress) {
1927 return HandleButtonPress(event);
1928 } else {
1929 return HandleButtonRelease(event);
1930 }
1931}
1932
1933////////////////////////////////////////////////////////////////////////////////
1934/// Resize events
1935
1937{
1938 if (fStop) {
1939 return kFALSE;
1940 }
1941
1942 TGWindow *w = fClient->GetWindowById(event->fWindow);
1943
1944 if (!w) {
1945 return kFALSE;
1946 }
1947
1949 return kFALSE;
1950}
1951
1952////////////////////////////////////////////////////////////////////////////////
1953/// Handle repaint event
1954
1956{
1957 if (fStop) {
1958 return kFALSE;
1959 }
1960
1961 static Long64_t was = gSystem->Now();
1962 static Window_t win = 0;
1963 Long64_t now = gSystem->Now();
1964
1965 if (event->fCount || (win == event->fWindow) || (now-was < 50) || fDragging) {
1966 if (fDragging) {
1968 }
1969 return kFALSE;
1970 }
1971
1972 if (gMenuDialog) {
1975 return kFALSE;
1976 }
1977
1978 if (fLassoDrawn) {
1979 DrawLasso();
1980 } else {
1981 if (IsSelectedVisible()) {
1983 }
1984 }
1985
1986 win = event->fWindow;
1987 was = now;
1988
1989 return kFALSE;
1990}
1991
1992////////////////////////////////////////////////////////////////////////////////
1993/// Handle all events.
1994
1996{
1997 if (fStop) {
1998 return kFALSE;
1999 }
2000
2001 if (IgnoreEvent(event)) {
2002 return kFALSE;
2003 }
2004
2005 switch (event->fType) {
2006
2007 case kExpose:
2008 return HandleExpose(event);
2009
2010 case kConfigureNotify:
2011 while (gVirtualX->CheckEvent(fId, kConfigureNotify, *event))
2012 ;
2014
2015 case kGKeyPress:
2016 case kKeyRelease:
2017 return HandleKey(event);
2018
2019 case kFocusIn:
2020 case kFocusOut:
2021 //HandleFocusChange(event);
2022 break;
2023
2024 case kButtonPress:
2025 {
2026 Int_t dbl_clk = kFALSE;
2027
2028 static Window_t gDbw = 0;
2029 static Long_t gLastClick = 0;
2030 static UInt_t gLastButton = 0;
2031 static Int_t gDbx = 0;
2032 static Int_t gDby = 0;
2033
2034 if ((event->fTime - gLastClick < 350) &&
2035 (event->fCode == gLastButton) &&
2036 (TMath::Abs(event->fXRoot - gDbx) < 6) &&
2037 (TMath::Abs(event->fYRoot - gDby) < 6) &&
2038 (event->fWindow == gDbw)) {
2039 dbl_clk = kTRUE;
2040 }
2041
2042 if (dbl_clk) {
2043 if (event->fState & kKeyControlMask) {
2045 return kTRUE;
2046 } else if (!(event->fState & 0xFF)) {
2047 TGFrame *w = (TGFrame*)fClient->GetWindowById(event->fWindow);
2048
2049 if (w && (w->GetEditDisabled() & kEditDisableBtnEnable)) {
2050 return w->HandleDoubleClick(event);
2051 }
2052 if (SaveFrame(fTmpBuildFile.Data())) {
2053 gROOT->Macro(fTmpBuildFile.Data());
2054 }
2055 // an easy way to start editting
2057 return kTRUE;
2058 }
2059 } else {
2060 gDbw = event->fWindow;
2061 gLastClick = event->fTime;
2062 gLastButton = event->fCode;
2063 gDbx = event->fXRoot;
2064 gDby = event->fYRoot;
2065
2067 return ret;
2068 }
2069
2070 return kFALSE;
2071 }
2072
2073 case kButtonRelease:
2074 return HandleButtonRelease(event);
2075
2076 case kEnterNotify:
2077 case kLeaveNotify:
2078 //HandleCrossing(event);
2079 break;
2080
2081 case kMotionNotify:
2082 while (gVirtualX->CheckEvent(fId, kMotionNotify, *event))
2083 ;
2084 return HandleMotion(event);
2085
2086 case kClientMessage:
2087 return HandleClientMessage(event);
2088
2089 case kDestroyNotify:
2090 return HandleDestroyNotify(event);
2091
2092 case kSelectionNotify:
2093 //HandleSelection(event);
2094 break;
2095
2096 case kSelectionRequest:
2097 //HandleSelectionRequest(event);
2098 break;
2099
2100 case kSelectionClear:
2101 //HandleSelectionClear(event);
2102 break;
2103
2104 case kColormapNotify:
2105 //HandleColormapChange(event);
2106 break;
2107
2108 default:
2109 //Warning("HandleEvent", "unknown event (%#x) for (%#x)", event->fType, fId);
2110 break;
2111 }
2112
2113 return kFALSE;
2114}
2115
2116////////////////////////////////////////////////////////////////////////////////
2117/// Mouse double click handler (never should happen)
2118
2120{
2121 if (fStop) {
2122 return kFALSE;
2123 }
2124
2125 return kFALSE;
2126}
2127
2128////////////////////////////////////////////////////////////////////////////////
2129/// Return a parent which can handle button events.
2130
2132{
2133 TGWindow *parent = fr;
2134
2135 while (parent && (parent != fClient->GetDefaultRoot())) {
2136 if (parent->GetEditDisabled() & kEditDisableBtnEnable) {
2137 return (TGFrame*)parent;
2138 }
2139 parent = (TGWindow*)parent->GetParent();
2140 }
2141 return 0;
2142}
2143
2144////////////////////////////////////////////////////////////////////////////////
2145/// Unmap all popups
2146
2148{
2149 TList *li = fClient->GetListOfPopups();
2150 if (!li->GetEntries()) {
2151 return;
2152 }
2153
2154 TGPopupMenu *pup;
2155 TIter next(li);
2156
2157 while ((pup = (TGPopupMenu*)next())) {
2158 pup->UnmapWindow();
2159 fClient->ResetWaitFor(pup);
2160 }
2161 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
2162}
2163
2164////////////////////////////////////////////////////////////////////////////////
2165/// Handle button press event
2166
2168{
2169 if (fStop) {
2170 return kFALSE;
2171 }
2172
2175
2176 if (fPimpl->fPlane) {
2179 }
2180
2181 if (gMenuDialog) { // keep editor on the top
2183 }
2184
2185 // keep undocked toolbar on the top
2186 //(but under win32 key handling will be broken : todo)
2187 if (gVirtualX->InheritsFrom("TGX11") && fBuilder &&
2190 }
2191
2192 // keep color dialog on the top
2195 return kFALSE;
2196 }
2197
2198 if ( ((event->fCode != kButton1) && (event->fCode != kButton3)) ||
2199 (event->fType != kButtonPress) || IgnoreEvent(event)) {
2200 return kFALSE;
2201 }
2202
2203 Reset1();
2204 //HideGrabRectangles();
2205
2206 Window_t w = GetWindowFromPoint(event->fXRoot, event->fYRoot);
2207 TGFrame *fr = 0;
2208
2209 if (w) {
2210 fr = (TGFrame*)fClient->GetWindowById(w);
2211 if (!fr) {
2212 return kFALSE;
2213 }
2214
2215 //fr->HandleButton(event);
2216 if (!IsEventsDisabled(fr)) {
2217 TGFrame *btnframe = GetBtnEnableParent(fr);
2218 if (btnframe) {
2219 event->fUser[0] = fr->GetId();
2220 btnframe->HandleButton(event);
2221 }
2222 }
2223
2224 if (IsGrabDisabled(fr)) {
2225 fr = GetEditableParent(fr);
2226 }
2227
2228 if (!fr) {
2229 return kFALSE;
2230 }
2231 } else {
2232 return kFALSE;
2233 }
2234
2235 return RecognizeGesture(event, fr);
2236}
2237
2238////////////////////////////////////////////////////////////////////////////////
2239/// Handle button release event
2240
2242{
2243 if (fStop) {
2244 return kFALSE;
2245 }
2246
2247 // unmap all waiting popups
2250 }
2251
2252 TGWindow *w = fClient->GetWindowById(event->fWindow);
2253
2254 if (w && !IsEventsDisabled(w)) {
2255 TGFrame *btnframe = GetBtnEnableParent((TGFrame*)w);
2256 if (btnframe) {
2257 event->fUser[0] = w->GetId();
2258 btnframe->HandleButton(event);
2259 }
2260 }
2261
2263 gVirtualX->SetCursor(fClient->GetRoot()->GetId(), gVirtualX->CreateCursor(kPointer));
2264 EndDrag();
2265 fSelectionIsOn &= (event->fState & kKeyShiftMask);
2266
2267 if (fLassoDrawn) {
2268 DrawLasso();
2269 return kTRUE;
2270 }
2271
2273
2274 // make editable the clicked frame if no lasso was drawn
2275 if ((fPimpl->fClickFrame == fPimpl->fGrab) && (fSelected == fPimpl->fGrab) &&
2276 !fPimpl->fGrab->IsEditable()) {
2278 return kTRUE;
2279
2280 // select/grab clicked frame if there was no grab frame
2281 } else if (!fPimpl->fGrab || ((fPimpl->fClickFrame != fPimpl->fGrab) &&
2282 (fPimpl->fClickFrame != fSelected))) {
2284 return kTRUE;
2285 }
2286
2287 }
2288
2290
2291 return kTRUE;
2292}
2293
2294////////////////////////////////////////////////////////////////////////////////
2295/// Handle key event
2296
2298{
2299 if (fStop) {
2300 return kFALSE;
2301 }
2302
2303 char tmp[10];
2304 UInt_t keysym;
2305 Bool_t ret = kFALSE;
2306 TGFileInfo fi;
2307 static TString dir(".");
2308 static Bool_t overwr = kFALSE;
2309 TString fname;
2310
2312
2313 if (!w || !fPimpl) {
2314 return kFALSE;
2315 }
2316
2317 if (w->GetEditDisabled() & kEditDisableKeyEnable) {
2318 return ((TGFrame*)w)->HandleKey(event);
2319 }
2320
2321 if (event->fType != kGKeyPress) {
2322 return kFALSE;
2323 }
2324
2325 if (IsEditDisabled(w)) {
2326 TGFrame *parent = GetEditableParent((TGFrame*)w);
2327 if (parent) {
2328 event->fWindow = parent->GetId();
2329 parent->HandleKey(event);
2330 } else {
2331 return ((TGFrame*)w)->HandleKey(event);
2332 }
2333 }
2334
2336
2337 if (fPimpl->fPlane) {
2340 }
2341
2342 CloseMenus();
2343
2345 fi.SetIniDir(dir);
2346 fi.fOverwrite = overwr;
2347
2348 gVirtualX->LookupString(event, tmp, sizeof(tmp), keysym);
2349
2350 if (event->fState & kKeyControlMask) {
2351
2352 switch ((EKeySym)keysym & ~0x20) {
2353 case kKey_Return:
2354 case kKey_Enter:
2356 ret = kTRUE;
2357 break;
2358 case kKey_X:
2359 HandleCut();
2360 ret = kTRUE;
2361 break;
2362 case kKey_C:
2363 HandleCopy();
2364 ret = kTRUE;
2365 break;
2366 case kKey_V:
2369 }
2370 HandlePaste();
2371 ret = kTRUE;
2372 break;
2373 case kKey_B:
2374 {
2375 if (fPimpl->fGrab ) {
2376 BreakLayout();
2377 }
2378 ret = kTRUE;
2379 break;
2380 }
2381 case kKey_L:
2382 {
2383 if (fPimpl->fGrab && (fPimpl->fClickFrame != fClient->GetRoot())) {
2384 Compact(kFALSE);
2385 } else {
2386 Compact(kTRUE);
2387 }
2388 ret = kTRUE;
2389 break;
2390 }
2391 case kKey_R:
2392 HandleReplace();
2393 ret = kTRUE;
2394 break;
2395 case kKey_S:
2396 Save();
2397 ret = kTRUE;
2398 break;
2399 case kKey_G:
2400 HandleGrid();
2401 ret = kTRUE;
2402 break;
2403 case kKey_H:
2404 SwitchLayout();
2405 ret = kTRUE;
2406 break;
2407 case kKey_N:
2408 if (fBuilder) {
2410 } else {
2411 TGMainFrame *main = new TGMainFrame(fClient->GetDefaultRoot(), 300, 300);
2412 main->MapRaised();
2413 main->SetEditable(kTRUE);
2414 }
2415 ret = kTRUE;
2416 break;
2417 case kKey_O:
2418 if (fBuilder) {
2420 } else {
2421 TGMainFrame *main = new TGMainFrame(fClient->GetDefaultRoot(), 300, 300);
2422 main->MapRaised();
2423 main->SetEditable(kTRUE);
2424 }
2425 new TGFileDialog(fClient->GetDefaultRoot(), this, kFDSave, &fi);
2426
2427 if (!fi.fFilename) return kTRUE;
2428 dir = fi.fIniDir;
2429 overwr = fi.fOverwrite;
2431
2432 if (fname.EndsWith(".C")) {
2433 gROOT->Macro(fname.Data());
2434 } else {
2435 Int_t retval;
2436 new TGMsgBox(fClient->GetDefaultRoot(), this, "Error...",
2437 TString::Format("file (%s) must have extension .C", fname.Data()),
2439 if (retval == kMBRetry) {
2441 }
2442 }
2443 ret = kTRUE;
2444 break;
2445 default:
2446 break;
2447 }
2448 } else {
2449 switch ((EKeySym)keysym) {
2450 case kKey_Delete:
2451 case kKey_Backspace:
2452 HandleDelete(event->fState & kKeyShiftMask);
2453 ret = kTRUE;
2454 break;
2455 case kKey_Return:
2456 case kKey_Enter:
2457 //UnmapAllPopups();
2459 ret = kTRUE;
2460 break;
2461 case kKey_Left:
2462 case kKey_Right:
2463 case kKey_Up:
2464 case kKey_Down:
2465 if (fLassoDrawn) {
2466 HandleAlignment(keysym, event->fState & kKeyShiftMask);
2467 } else if (fPimpl->fGrab) {
2468 HandleLayoutOrder((keysym == kKey_Right) || (keysym == kKey_Down));
2469 }
2470 ret = kTRUE;
2471 break;
2472 case kKey_Space:
2473 //UnmapAllPopups();
2474 if (fPimpl->fGrab) {
2476
2478
2479 if (p) {
2480 if (fBuilder && p == fBuilder->GetMdiMain()->GetCurrent()) {
2481 UngrabFrame();
2482 } else {
2483 SelectFrame(p);
2485 }
2486 }
2487 }
2488 ret = kTRUE;
2489 break;
2490 default:
2491 break;
2492 }
2493 }
2494 if (fBuilder) {
2495 fBuilder->SetAction(0);
2496 //fBuilder->Update();
2497 }
2498
2499 if (fLassoDrawn) {
2500 DrawLasso();
2501 }
2502
2503 return ret;
2504}
2505
2506////////////////////////////////////////////////////////////////////////////////
2507/// Reparent frames
2508
2510{
2511 if (fStop || !fClient->IsEditable() || (newfr == fClient->GetDefaultRoot())) {
2512 return;
2513 }
2514
2515 Int_t x0, y0, xx, yy;
2516 Window_t c;
2517 static TGLayoutHints *hints = new TGLayoutHints(kLHintsNormal, 2, 2, 2, 2);
2518
2519 if (!newfr || !newfr->GetId() || !oldfr || !oldfr->GetId()) return;
2520
2521 gVirtualX->TranslateCoordinates(newfr->GetId(), oldfr->GetId(),
2522 0, 0, x0, y0, c);
2523
2524 x0 = x0 < 0 ? 0 : x0;
2525 y0 = y0 < 0 ? 0 : y0;
2526 Int_t x = x0 + newfr->GetWidth();
2527 Int_t y = y0 + newfr->GetHeight();
2528
2529 TGCompositeFrame *comp = 0;
2530
2531 if (newfr->InheritsFrom(TGCompositeFrame::Class())) {
2532 comp = (TGCompositeFrame*)newfr;
2533 comp->SetLayoutBroken();
2534 }
2535
2536 TIter next(oldfr->GetList());
2537 TGFrameElement *el;
2538
2539 while ((el = (TGFrameElement*)next())) {
2540 TGFrame *frame = el->fFrame;
2541
2542 if ((frame->GetX() >= x0) && (frame->GetY() >= y0) &&
2543 (frame->GetX() + (Int_t)frame->GetWidth() <= x) &&
2544 (frame->GetY() + (Int_t)frame->GetHeight() <= y)) {
2545
2546 if (frame == fPimpl->fGrab) {
2547 UngrabFrame();
2548 }
2549
2550 oldfr->RemoveFrame(frame);
2551
2552 gVirtualX->TranslateCoordinates(oldfr->GetId(), newfr->GetId(),
2553 frame->GetX(), frame->GetY(), xx, yy, c);
2554
2555 frame->ReparentWindow(newfr, xx, yy);
2556
2557 if (comp) {
2558 comp->AddFrame(frame, hints); // el->fLayout);
2559 }
2560 }
2561 }
2562}
2563
2564////////////////////////////////////////////////////////////////////////////////
2565/// Return the list of frames inside of some area
2566
2568{
2569 if (fStop) {
2570 return 0;
2571 }
2572
2573 Int_t xx, yy;
2574
2576 return 0;
2577 }
2578
2579 TList *list = new TList();
2580
2581 xx = x0; yy = y0;
2582 x0 = TMath::Min(xx, x); x = TMath::Max(xx, x);
2583 y0 = TMath::Min(yy, y); y = TMath::Max(yy, y);
2584
2585 TIter next(((TGCompositeFrame*)fClient->GetRoot())->GetList());
2586 TGFrameElement *el;
2587
2588 while ((el = (TGFrameElement*)next())) {
2589 if ((el->fFrame->GetX() >= x0) && (el->fFrame->GetY() >= y0) &&
2590 (el->fFrame->GetX() + (Int_t)el->fFrame->GetWidth() <= x) &&
2591 (el->fFrame->GetY() + (Int_t)el->fFrame->GetHeight() <= y)) {
2592 list->Add(el->fFrame);
2593 }
2594 }
2595 if (list->IsEmpty()) {
2596 delete list;
2597 return 0;
2598 }
2599 return list;
2600}
2601
2602////////////////////////////////////////////////////////////////////////////////
2603/// Drop canvas container
2604
2606{
2607 if (fStop) {
2608 return;
2609 }
2610
2611 TGCompositeFrame *comp = (TGCompositeFrame*)canvas->GetParent();
2612 comp->SetEditable(kTRUE);
2613
2615 Int_t x = canvas->GetX();
2616 Int_t y = canvas->GetY();
2617
2618 cont->SetEditDisabled(cont->GetEditDisabled() & ~kEditDisableGrab);
2619 cont->ReparentWindow(comp, x, y);
2620 canvas->SetContainer(0);
2621 comp->AddFrame(cont);
2622 DeleteFrame(canvas);
2623
2624 if (fBuilder) {
2625 TString str = cont->ClassName();
2626 str += "::";
2627 str += cont->GetName();
2628 str += " dropped.";
2630 }
2631 SelectFrame(cont);
2632}
2633
2634////////////////////////////////////////////////////////////////////////////////
2635/// Create a new TGCanvas and place container into it
2636
2638{
2639 if (fStop || !cont) {
2640 return;
2641 }
2642
2644 comp->SetEditable(kTRUE);
2645
2646 UInt_t w = cont->GetWidth()/2;
2647 UInt_t h = cont->GetHeight()/2;
2648
2649 w = w < 100 ? 100 : w;
2650 h = h < 100 ? 100 : h;
2651
2652 TGCanvas *canvas = new TGCanvas(comp, w, h);
2653 canvas->Move(cont->GetX(), cont->GetY());
2654 comp->RemoveFrame(cont);
2655 comp->AddFrame(canvas);
2656 cont->ReparentWindow(canvas->GetViewPort());
2657 canvas->SetContainer(cont);
2658 cont->SetCleanup(kDeepCleanup);
2659 canvas->MapSubwindows();
2660 canvas->MapWindow();
2661 SelectFrame(canvas);
2662
2663 if (fBuilder) {
2664 fBuilder->UpdateStatusBar("Grab action performed. Press Cntrl-Return to Drop grabbed frame.");
2665 }
2666}
2667
2668////////////////////////////////////////////////////////////////////////////////
2669/// Handling of return/enter key pressing
2670///
2671/// If on is kFALSE:
2672/// If Return or Enter key was pressed - Grab Act
2673/// If lasso is drawn - new composite frame is created and
2674/// all frames inside lasso adopted as children.
2675/// If lasso is not drawn and selected frame is composite one,
2676/// - new TGCanvas widget is created and selected frame became
2677/// container for this canvas.
2678///
2679/// If on is kTRUE:
2680/// If Return or Enter key was pressed with Control Key - Drop Act,
2681/// The opposite action to the Grab Act.
2682/// If selected/grabbed frame is not a TGCanvas widget -
2683/// all frames inside the grabbed/selected frame are "dropped" into
2684/// the underlying frame and the grabbed frame is deleted.
2685///
2686/// If selected/grabbed frame is a TGCanvas widget -
2687/// container frame "dropped" to editable frame
2688
2690{
2691 if (fStop) {
2692 return;
2693 }
2694
2695 Int_t x0, y0, x, y, xx, yy;
2696 Window_t c;
2697 TGCompositeFrame *parent = 0;
2698 TList *li = 0;
2699
2701 !fClient->IsEditable()) {
2702 return;
2703 }
2704
2705 // if grabbed frame is editable - we need to switch edit to parent
2706 if (fPimpl->fGrab && fPimpl->fGrab->IsEditable()) {
2708 }
2709
2710 if (fPimpl->fGrab && !fLassoDrawn) {
2711 if (!on) {
2718 return;
2719 }
2720 } else {
2721
2722 if ((fPimpl->fGrab->IsA() == TGCanvas::Class()) &&
2723 !((TGCanvas*)fPimpl->fGrab)->GetContainer()->InheritsFrom(TGContainer::Class()) &&
2726 return;
2727 }
2728 }
2729 }
2730
2732
2733 if (fLassoDrawn) {
2734
2735 gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(),
2736 fClient->GetRoot()->GetId(),
2737 fPimpl->fX, fPimpl->fY, x, y, c);
2738 gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(),
2739 fClient->GetRoot()->GetId(),
2740 fPimpl->fX0, fPimpl->fY0, x0, y0, c);
2741
2742 xx = x0; yy = y0;
2743 x0 = TMath::Min(xx, x); x = TMath::Max(xx, x);
2744 y0 = TMath::Min(yy, y); y = TMath::Max(yy, y);
2745
2746 li = GetFramesInside(x0, y0, x, y);
2747
2748 if (!on && li) {
2749 parent = new TGCompositeFrame(comp, x - x0, y - y0);
2750 parent->MoveResize(x0, y0, x - x0, y - y0);
2751 ReparentFrames(parent, comp);
2752
2753 comp->AddFrame(parent);
2754 parent->MapWindow();
2756 SelectFrame(parent);
2757
2758 if (fBuilder) {
2759 TString str = "Grab action performed.";
2760 str += " Press Cntrl-Return to Drop grabbed frames.";
2761 str += " Press Return for TCanvas Grab";
2763 }
2764 }
2765 } else if (on && fPimpl->fGrab) {
2766
2767 // check if it is forbidden
2768 if (!CanChangeLayout(fPimpl->fGrab) ||
2770 if (fBuilder) {
2771 fBuilder->UpdateStatusBar("Drop action disabled");
2772 }
2773 return;
2774 }
2775
2777 parent = (TGCompositeFrame*)fPimpl->fGrab;
2778 } else {
2779 //parent = (TGCompositeFrame*)fPimpl->fGrab->GetParent();
2780 }
2781 if (parent) {
2782 ReparentFrames(comp, parent);
2784 UngrabFrame();
2785 ChangeSelected(0); //update editors
2786
2787 if (fBuilder) {
2788 fBuilder->UpdateStatusBar("Drop action performed");
2789 }
2790 }
2791 }
2792 delete li;
2793}
2794
2795////////////////////////////////////////////////////////////////////////////////
2796/// Align frames located inside lasso area.
2797
2799{
2800 if (fStop) {
2801 return;
2802 }
2803
2804 Int_t x0, y0, x, y, xx, yy;
2805 Window_t c;
2806 TGCompositeFrame *comp = 0;
2807
2809 !fClient->IsEditable()) {
2810 return;
2811 }
2812
2813 if (fLassoDrawn) {
2814 gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(),
2815 fClient->GetRoot()->GetId(),
2816 fPimpl->fX, fPimpl->fY, x, y, c);
2817 gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(),
2818 fClient->GetRoot()->GetId(),
2819 fPimpl->fX0, fPimpl->fY0, x0, y0, c);
2820
2821 xx = x0; yy = y0;
2822 x0 = TMath::Min(xx, x); x = TMath::Max(xx, x);
2823 y0 = TMath::Min(yy, y); y = TMath::Max(yy, y);
2824
2825 comp = (TGCompositeFrame*)fClient->GetRoot();
2826
2827 ToGrid(x, y);
2828 ToGrid(x0, y0);
2829
2830 TIter next(comp->GetList());
2831 TGFrameElement *el;
2832 TGFrame *prev = 0;
2833
2834 while ((el = (TGFrameElement*)next())) {
2835 TGFrame *fr = el->fFrame;
2836
2837 if ((fr->GetX() >= x0) && (fr->GetY() >= y0) &&
2838 (fr->GetX() + (Int_t)fr->GetWidth() <= x) &&
2839 (fr->GetY() + (Int_t)fr->GetHeight() <= y)) {
2840
2841 switch ((EKeySym)to) {
2842 case kKey_Left:
2843 fr->Move(x0, fr->GetY());
2844 if (lineup) {
2845 // coverity[dead_error_line]
2846 if (prev) fr->Move(fr->GetX(), prev->GetY() + prev->GetHeight());
2847 else fr->Move(x0, y0);
2848 }
2849 break;
2850 case kKey_Right:
2851 fr->Move(x - fr->GetWidth(), fr->GetY());
2852 if (lineup) {
2853 if (prev) fr->Move(fr->GetX(), prev->GetY() + prev->GetHeight());
2854 else fr->Move(x - fr->GetWidth(), y0);
2855 }
2856 break;
2857 case kKey_Up:
2858 fr->Move(fr->GetX(), y0);
2859 if (lineup) {
2860 if (prev) fr->Move(prev->GetX() + prev->GetWidth(), fr->GetY());
2861 else fr->Move(x0, y0);
2862 }
2863 break;
2864 case kKey_Down:
2865 fr->Move(fr->GetX(), y - fr->GetHeight());
2866 if (lineup) {
2867 if (prev) fr->Move(prev->GetX() + prev->GetWidth(), fr->GetY());
2868 else fr->Move(x0, y - fr->GetHeight());
2869 }
2870 break;
2871 default:
2872 break;
2873 }
2874 prev = fr;
2875 }
2876 }
2877 }
2878 if (fLassoDrawn) {
2879 DrawLasso();
2880 }
2881}
2882
2883////////////////////////////////////////////////////////////////////////////////
2884/// Handle delete or crop action
2885///
2886/// crop is kFALSE - delete action
2887/// - if lasso is drawn -> all frames inside lasso area are deleted
2888/// - if frame is grabbed/selected -> the frame is deleted
2889/// crop is kTRUE - crop action
2890/// - if lasso is drawn -> all frames outside of lasso area are deleted
2891/// - if frame is grabbed/selected -> all frames except the grabbed frame are deleted
2892/// In both cases the main frame is shrunk to the size of crop area.
2893
2895{
2896 if (fStop) {
2897 return;
2898 }
2899
2900 Int_t x0, y0, x, y, xx, yy, w, h;
2901 Window_t c;
2902
2904 !fClient->IsEditable()) {
2905 return;
2906 }
2907
2908 TGCompositeFrame *comp = 0;
2909 Bool_t fromGrab = kFALSE;
2910 TGFrame *frame = fPimpl->fGrab;
2911
2912 if (fBuilder && crop) {
2914 } else {
2915 comp = (TGCompositeFrame*)fClient->GetRoot();
2916 }
2917
2918 if (frame && !CanChangeLayout((TGWindow*)frame->GetParent())) {
2919 frame = GetMovableParent(frame);
2920
2921 if (!frame) {
2922 TString str = fPimpl->fGrab->ClassName();
2923 str += "::";
2924 str += fPimpl->fGrab->GetName();
2925 str += " cannot be deleted";
2926
2927 if (fBuilder) {
2929 }
2930 return;
2931 }
2932 }
2933
2934 // prepare to crop grabbed frame
2935 if (frame && !fLassoDrawn && crop) {
2936 gVirtualX->TranslateCoordinates(frame->GetId(),
2938 -2, -2,
2939 fPimpl->fX0, fPimpl->fY0, c);
2940
2941 fPimpl->fX = fPimpl->fX0 + frame->GetWidth()+4;
2942 fPimpl->fY = fPimpl->fY0 + frame->GetHeight()+4;
2943 fromGrab = kTRUE;
2944 }
2945
2946 x0 = fPimpl->fX0; y0 = fPimpl->fY0;
2947 x = fPimpl->fX; y = fPimpl->fY;
2948 if (comp) {
2949 gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(),
2950 comp->GetId(),
2951 fPimpl->fX, fPimpl->fY, x, y, c);
2952 gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(),
2953 comp->GetId(),
2954 fPimpl->fX0, fPimpl->fY0, x0, y0, c);
2955 }
2956
2957 xx = x0; yy = y0;
2958 x0 = TMath::Min(xx, x); x = TMath::Max(xx, x);
2959 y0 = TMath::Min(yy, y); y = TMath::Max(yy, y);
2960 w = x - x0;
2961 h = y - y0;
2962
2963 if (fLassoDrawn || fromGrab) {
2964 if (comp) {
2965 TIter next(comp->GetList());
2966 TGFrameElement *el;
2967
2968 while ((el = (TGFrameElement*)next())) {
2969 TGFrame *fr = el->fFrame;
2970
2971 if ((fr->GetX() >= x0) && (fr->GetY() >= y0) &&
2972 (fr->GetX() + (Int_t)fr->GetWidth() <= x) &&
2973 (fr->GetY() + (Int_t)fr->GetHeight() <= y)) {
2974 if (!crop) {
2975 DeleteFrame(fr);
2976 } else {
2977 fr->Move(fr->GetX() - x0, fr->GetY() - y0);
2978 }
2979 } else {
2980 if (crop) {
2981 DeleteFrame(fr);
2982 }
2983 }
2984 }
2985 if (crop && comp) {
2986 gVirtualX->TranslateCoordinates(comp->GetId(), comp->GetParent()->GetId(),
2987 x0, y0, xx, yy, c);
2988
2989 comp->MoveResize(xx, yy, w, h);
2990
2992 TGMdiDecorFrame *decor = (TGMdiDecorFrame *)comp->GetParent();
2993
2994 gVirtualX->TranslateCoordinates(decor->GetId(), decor->GetParent()->GetId(),
2995 xx, yy, xx, yy, c);
2996
2997 Int_t b = 2 * decor->GetBorderWidth();
2998 decor->MoveResize(xx, yy, comp->GetWidth() + b,
2999 comp->GetHeight() + b + decor->GetTitleBar()->GetDefaultHeight());
3000 }
3001 }
3002 }
3003 } else { // no lasso drawn -> delete selected frame
3004 if (frame)
3005 DeleteFrame(frame);
3006 UngrabFrame();
3007 ChangeSelected(0); //update editors
3008 }
3010
3011 if (fBuilder) {
3012 //fBuilder->Update();
3013 fBuilder->UpdateStatusBar(crop ? "Crop action performed" : "Delete action performed");
3014 }
3015}
3016
3017////////////////////////////////////////////////////////////////////////////////
3018/// Delete frame
3019
3021{
3022 if (fStop || !frame) {
3023 return;
3024 }
3025
3026 // remove the frame from the list tree and reset the editor...
3027 fEditor->RemoveFrame(frame);
3028
3029 frame->UnmapWindow();
3030
3031 TGCompositeFrame *comp = 0;
3032
3034 comp = (TGCompositeFrame*)frame->GetParent();
3035 }
3036
3037 if (comp) {
3038 comp->RemoveFrame(frame);
3039 }
3040
3041 if (frame == fPimpl->fGrab) {
3042 UngrabFrame();
3043 }
3044
3045 fClient->UnregisterWindow(frame);
3046
3047 // mem.leak paid for robustness (with possibility "undelete")
3049}
3050
3051////////////////////////////////////////////////////////////////////////////////
3052/// Handle cut action
3053
3055{
3056 if (fStop || !fPimpl->fGrab) {
3057 return;
3058 }
3059
3060 //
3062 HandleCopy();
3064 ChangeSelected(0); //update editors
3065}
3066
3067////////////////////////////////////////////////////////////////////////////////
3068/// Handle copy. This method is also used by SaveFrame method.
3069/// In later case brk_layout == kFALSE
3070
3072{
3073 if (fStop || !fPimpl->fGrab) {
3074 return;
3075 }
3076
3078 fPimpl->fGrab->GetWidth(),
3079 fPimpl->fGrab->GetHeight());
3080
3081 // save coordinates
3082 Int_t x0 = fPimpl->fGrab->GetX();
3083 Int_t y0 = fPimpl->fGrab->GetY();
3084
3085 // save parent name
3087
3088 ((TGWindow*)fPimpl->fGrab->GetParent())->SetName(tmp->GetName());
3089
3090 fPimpl->fGrab->SetX(0);
3091 fPimpl->fGrab->SetY(0);
3092
3094
3095 if (fe) {
3096 tmp->GetList()->Add(fe);
3097 }
3098
3099 tmp->SetLayoutBroken(brk_layout);
3100
3101 if (!brk_layout) { //save frame
3103 tmp->SetWMSize(tmp->GetWidth(), tmp->GetHeight());
3104 tmp->SetWMSizeHints(tmp->GetDefaultWidth(), tmp->GetDefaultHeight(), 10000, 10000, 0, 0);
3105 const char *short_name = gSystem->BaseName(fPasteFileName.Data());
3106 tmp->SetWindowName(short_name);
3107 tmp->SetIconName(short_name);
3108 tmp->SetClassHints(short_name, short_name);
3109 // some problems here under win32
3110 if (gVirtualX->InheritsFrom("TGX11")) tmp->SetIconPixmap("bld_rgb.xpm");
3111 }
3112 Bool_t quite = brk_layout || (fPasteFileName == fTmpBuildFile);
3113 tmp->SaveSource(fPasteFileName.Data(), quite ? "keep_names quiet" : "keep_names");
3114 tmp->GetList()->Remove(fe);
3115
3116 fPimpl->fGrab->SetX(x0);
3117 fPimpl->fGrab->SetY(y0);
3118
3119 ((TGWindow*)fPimpl->fGrab->GetParent())->SetName(name.Data());
3120
3121 if (fBuilder) {
3122 TString str = fPimpl->fGrab->ClassName();
3123 str += "::";
3124 str += fPimpl->fGrab->GetName();
3125 str += " copied to clipboard";
3127 }
3128
3129 delete tmp;
3130}
3131
3132////////////////////////////////////////////////////////////////////////////////
3133/// Handle paste action.
3134
3136{
3137 if (fStop) {
3138 return;
3139 }
3140
3141 Int_t xp = 0;
3142 Int_t yp = 0;
3143
3145 return;
3146 }
3147
3148 fPasting = kTRUE;
3149 gROOT->Macro(fPasteFileName.Data());
3150
3151 Window_t c;
3152 TGFrame *root = (TGFrame*)fClient->GetRoot();
3153
3154 if (!fPimpl->fReplaceOn) {
3155 gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(),
3156 root->GetId(),
3157 fPimpl->fX0, fPimpl->fY0, xp, yp, c);
3158 ToGrid(xp, yp);
3159
3160 // fPasteFrame is defined in TVirtualDragManager.h
3161 // fPasteFrame is a TGMainFrame consisting "the frame to paste"
3162 // into the editable frame (aka fClient->GetRoot())
3163
3164 if (fPasteFrame) {
3166 TGFrame *paste = ((TGFrameElement*)main->GetList()->First())->fFrame;
3167
3168 UInt_t w = paste->GetWidth();
3169 UInt_t h = paste->GetHeight();
3170
3171 if (xp + w > root->GetWidth()) {
3172 w = root->GetWidth() - xp -1;
3173 }
3174 if (yp + h > root->GetHeight()) {
3175 h = root->GetHeight() - yp -1;
3176 }
3177
3178 paste->Resize(w, h);
3179 fPasteFrame->Move(xp, yp);
3181 HandleReturn(1); // drop
3182 }
3183 }
3184
3185 fPasting = kFALSE;
3186
3187 if (fBuilder) {
3188 fBuilder->UpdateStatusBar("Paste action performed");
3189 }
3190}
3191
3192////////////////////////////////////////////////////////////////////////////////
3193/// Replace frame (doesn't work yet properly)
3194
3196{
3197 if (fStop || !frame || !fPimpl->fGrab || !fPimpl->fReplaceOn) {
3198 return;
3199 }
3200
3201 Int_t w = fPimpl->fGrab->GetWidth();
3203 Int_t x = fPimpl->fGrab->GetX();
3204 Int_t y = fPimpl->fGrab->GetY();
3205
3206 if (fBuilder) {
3207 TString str = fPimpl->fGrab->ClassName();
3208 str += "::";
3209 str += fPimpl->fGrab->GetName();
3210 str += " replaced by ";
3211 str += frame->ClassName();
3212 str += "::";
3213 str += frame->GetName();
3215 }
3216
3218
3219 if (fe) {
3220 fe->fFrame = 0;
3222 delete fPimpl->fGrab;
3223 fPimpl->fGrab = 0;
3224
3225 fe->fFrame = frame;
3226 frame->MoveResize(x, y, w, h);
3227 frame->MapRaised();
3228 frame->SetFrameElement(fe);
3229 }
3230
3231 SelectFrame(frame);
3233
3234 TGWindow *root = (TGWindow *)fClient->GetRoot();
3235 root->SetEditable(kFALSE);
3236 DoRedraw();
3237 root->SetEditable(kTRUE);
3238}
3239
3240////////////////////////////////////////////////////////////////////////////////
3241/// Handle replace
3242
3244{
3245 if (fStop || !fPimpl->fGrab) {
3246 return;
3247 }
3248
3250 TGFrame *frame = 0;
3251
3252 if (fBuilder && fBuilder->IsExecutable()) {
3253 frame = (TGFrame *)fBuilder->ExecuteAction();
3254 } else {
3255 HandlePaste();
3256 frame = fPasteFrame;
3257 }
3258 DoReplace(frame);
3260}
3261
3262////////////////////////////////////////////////////////////////////////////////
3263/// Create a frame which is the same as currently edited frame
3264
3266{
3267 if (fStop) {
3268 return;
3269 }
3270
3271 TString tmpfile = gSystem->TempDirectory();
3272 char *s = gSystem->ConcatFileName(tmpfile.Data(), TString::Format("tmp%d.C",
3273 gRandom->Integer(100)));
3274 Save(s);
3275 gROOT->Macro(s);
3276 gSystem->Unlink(s);
3277 delete [] s;
3278
3280 TGFrame *f = (TGFrame *)fClient->GetRoot();
3281 f->Resize(f->GetWidth() + 10, f->GetHeight() + 10);
3282 }
3283}
3284
3285////////////////////////////////////////////////////////////////////////////////
3286/// Save an edited frame to the file
3287
3289{
3290 if (fStop || !fClient->GetRoot() || !fClient->IsEditable()) {
3291 return kFALSE;
3292 }
3293
3295 TGWindow *root = (TGWindow*)fClient->GetRoot();
3296 TString fname = file;
3297
3298 root->SetEditable(kFALSE);
3299
3300 static TImage *img = 0;
3301
3302 if (!img) {
3303 img = TImage::Create();
3304 }
3305 img->FromWindow(main->GetId());
3306
3307 if (!file || !file[0]) {
3308 static TString dir(".");
3309 static Bool_t overwr = kFALSE;
3310 TGFileInfo fi;
3311
3313 fi.SetIniDir(dir);
3314 fi.fOverwrite = overwr;
3315 new TGFileDialog(fClient->GetDefaultRoot(), this, kFDSave, &fi);
3316
3317 if (!fi.fFilename) goto out;
3318 dir = fi.fIniDir;
3319 overwr = fi.fOverwrite;
3321 }
3322
3323 if (fname.EndsWith(".C")) {
3325 main->SetWMSize(main->GetWidth(), main->GetHeight());
3326 main->SetWMSizeHints(main->GetDefaultWidth(), main->GetDefaultHeight(), 10000, 10000, 0, 0);
3327 main->SetWindowName(fname.Data());
3328 main->SetIconName(fname.Data());
3329 main->SetClassHints(fname.Data(), fname.Data());
3330 // some problems here under win32
3331 if (gVirtualX->InheritsFrom("TGX11")) main->SetIconPixmap("bld_rgb.xpm");
3332 main->SaveSource(fname.Data(), file ? "keep_names quiet" : "keep_names");
3333
3334 if (fBuilder)
3335 fBuilder->AddMacro(fname.Data(), img);
3336
3337 } else {
3338 Int_t retval;
3339 TString msg = TString::Format("file (%s) must have extension .C", fname.Data());
3340
3341 new TGMsgBox(fClient->GetDefaultRoot(), main, "Error...", msg.Data(),
3343
3344 if (retval == kMBRetry) {
3345 return Save();
3346 }
3347 }
3348
3349out:
3350 main->RaiseWindow();
3351 return kTRUE;
3352}
3353
3354////////////////////////////////////////////////////////////////////////////////
3355/// Save composite frame as macro
3356
3358{
3359 if (fStop || !fClient->GetRoot() || !fClient->IsEditable() ||
3361 return kFALSE;
3362 }
3363
3364 TString fname = file;
3365
3366 TGFrame *frame = fPimpl->fGrab;
3368
3369 static TImage *img = 0;
3370
3371 if (!img) {
3372 img = TImage::Create();
3373 }
3374 img->FromWindow(frame->GetId());
3375
3376 static TString dir(".");
3377 static Bool_t overwr = kFALSE;
3378
3379 TString sav = fPasteFileName;
3380
3381 if (!file) {
3382 TGFileInfo fi;
3383
3385 fi.SetIniDir(dir);
3386 fi.fOverwrite = overwr;
3387 new TGFileDialog(fClient->GetDefaultRoot(), frame, kFDSave, &fi);
3388
3389 if (!fi.fFilename) {
3390 goto out;
3391 }
3392
3393 dir = fi.fIniDir;
3394 overwr = fi.fOverwrite;
3396 }
3397
3398 if (fname.EndsWith(".C")) {
3399 fPasteFileName = fname;
3400 fPimpl->fGrab = frame;
3401 fStop = kFALSE;
3402 TGFrameElement *fe = frame->GetFrameElement();
3403
3404 if (!fe) { // should never happen
3405 fe = new TGFrameElement();
3406 fe->fFrame = frame;
3407 fe->fState = kIsMapped;
3408 frame->SetFrameElement(fe);
3409 TGCompositeFrame *comp = (TGCompositeFrame*)frame->GetParent();
3410 comp->GetList()->Add(fe);
3411 }
3412 delete fe->fLayout;
3414
3416 fStop = kTRUE;
3417
3418 fBuilder->AddMacro(fname.Data(), img);
3419 } else {
3420 Int_t retval;
3421 TString msg = TString::Format("file (%s) must have extension .C", fname.Data());
3422
3423 new TGMsgBox(fClient->GetDefaultRoot(), frame, "Error...", msg.Data(),
3425
3426 if (retval == kMBRetry) {
3427 return SaveFrame();
3428 }
3429 }
3430
3431out:
3432 fPasteFileName = sav;
3433 return kTRUE;
3434}
3435/*
3436////////////////////////////////////////////////////////////////////////////////
3437/// Not used yet. Return 0 if all child frames are inside area x,y, w,h
3438
3439static Int_t canResize(TGFrame *frame, Int_t x, Int_t y, UInt_t &w, UInt_t &h)
3440{
3441 if (frame->InheritsFrom(TGCompositeFrame::Class())) return 0;
3442
3443 TGCompositeFrame *comp = (TGCompositeFrame*)frame;
3444
3445 TIter next(comp->GetList());
3446 TGFrameElement *fe;
3447 Int_t d = gGuiBldDragManager->GetGridStep();
3448 Int_t ret = 0;
3449
3450 while ((fe = (TGFrameElement*)next())) {
3451 if (x + fe->fFrame->GetX() + fe->fFrame->GetWidth() > w) {
3452 w = fe->fFrame->GetX() + x + fe->fFrame->GetWidth();
3453 ret |= 4;
3454 }
3455 if (y + fe->fFrame->GetY() + fe->fFrame->GetHeight() > h) {
3456 h = fe->fFrame->GetY() + y + fe->fFrame->GetHeight();
3457 ret |= 8;
3458 }
3459 }
3460 return ret;
3461}
3462*/
3463
3464////////////////////////////////////////////////////////////////////////////////
3465/// handle resize
3466
3468{
3469 if (fStop || !fClient->IsEditable()) {
3470 return;
3471 }
3472
3473 TGFrame *fr = fPimpl->fGrab;
3474
3475 if (!fr || IsFixedSize(fr) ||
3476 IsFixedLayout((TGWindow*)fr->GetParent())) {
3477
3478 fr = (TGFrame*)GetResizableParent(fr);
3479
3480 if (!fr ) {
3481 return;
3482 }
3483 }
3484
3485 TGCompositeFrame *comp = 0;
3486
3488 comp = (TGCompositeFrame*)fr;
3489 }
3490
3491 Window_t c;
3492 Int_t x = fPimpl->fX;
3493 Int_t y = fPimpl->fY;
3494 UInt_t w = 0;
3495 UInt_t h = 0;
3496 UInt_t wp = ((TGFrame*)fr->GetParent())->GetWidth() - 2;
3497 UInt_t hp = ((TGFrame*)fr->GetParent())->GetHeight() - 2;
3498
3499 gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(),
3500 fr->GetId(), x, y, x, y, c);
3501
3502 ToGrid(x, y);
3504
3505 switch (fPimpl->fResizeType) {
3506 case kTopLeft:
3507 if ((((int)fr->GetWidth() > x) || (x < 0)) &&
3508 (((int)fr->GetHeight() > y) || (y < 0))) {
3509
3510 if (fr->GetY() + y < 2) {
3511 y = 2 - fr->GetY();
3512 }
3513 if (fr->GetX() + x < 2) {
3514 x = 2 - fr->GetX();
3515 }
3516 h = fr->GetHeight() - y;
3517 w = fr->GetWidth() - x;
3518 x = fr->GetX() + x;
3519 y = fr->GetY() + y;
3520
3521 if (!IsFixedH(fr) && !IsFixedW(fr)) {
3522 fr->MoveResize(x, y, w, h);
3523 break;
3524 }
3525 if (IsFixedH(fr)) {
3526 fr->MoveResize(x, fr->GetY(), w, fr->GetDefaultHeight());
3527 break;
3528 }
3529 if (IsFixedW(fr)) {
3530 fr->MoveResize(fr->GetX(), y, fr->GetDefaultWidth(), h);
3531 break;
3532 }
3533 }
3534 break;
3535 case kTopRight:
3536 if ((x > 0) && (((int)fr->GetHeight() > y) || (y < 0))) {
3537
3538 if (fr->GetY() + y < 2) {
3539 y = 2 - fr->GetY();
3540 }
3541 h = fr->GetHeight() - y;
3542
3543 if (IsFixedW(fr)) {
3544 w = fr->GetDefaultWidth();
3545 } else {
3546 w = fr->GetX() + x > Int_t(wp) ? wp - fr->GetX() : UInt_t(x);
3547 }
3548 x = fr->GetX();
3549 y = fr->GetY() + y;
3550
3551 if (!IsFixedH(fr)) {
3552 fr->MoveResize(x, y, w, h);
3553 } else {
3554 fr->Resize(x, fr->GetDefaultHeight());
3555 }
3556 }
3557 break;
3558 case kTopSide:
3559 if (((int)fr->GetHeight() > y) || (y < 0)) {
3560 if (IsFixedH(fr)) {
3561 break;
3562 }
3563
3564 if (fr->GetY() + y < 2) {
3565 y = 2 - fr->GetY();
3566 }
3567 h = fr->GetHeight() - y;
3568 w = fr->GetWidth();
3569 x = fr->GetX();
3570 y = fr->GetY() + y;
3571
3572 fr->MoveResize(x, y, w, h);
3573 }
3574 break;
3575 case kBottomLeft:
3576 if ((((int)fr->GetWidth() > x) || (x < 0)) && (y > 0)) {
3577
3578 if (fr->GetX() + x < 2) {
3579 x = 2 - fr->GetX();
3580 }
3581 h = fr->GetY() + y > Int_t(hp) ? hp - fr->GetY() : UInt_t(y);
3582 w = fr->GetWidth() - x;
3583 x = fr->GetX() + x;
3584
3585 if (!IsFixedH(fr) && !IsFixedW(fr)) {
3586 fr->MoveResize(x, fr->GetY(), w, h);
3587 break;
3588 }
3589 if (IsFixedH(fr)) {
3590 fr->MoveResize(x, fr->GetY(), w, fr->GetDefaultHeight());
3591 break;
3592 }
3593 if (IsFixedW(fr)) {
3594 fr->MoveResize(fr->GetX(), fr->GetY(),
3595 fr->GetDefaultWidth(), h);
3596 break;
3597 }
3598 }
3599 break;
3600 case kBottomRight:
3601 if ((x > 0) && (y > 0)) {
3602 w = !IsFixedW(fr) ? UInt_t(x) : fr->GetDefaultWidth();
3603 h = !IsFixedH(fr) ? UInt_t(y) : fr->GetDefaultHeight();
3604
3605 h = fr->GetY() + h > hp ? hp - fr->GetY() : h;
3606 w = fr->GetX() + w > wp ? wp - fr->GetX() : w;
3607
3608 //canResize(comp, 0, 0, w, h);
3609 fr->Resize(w, h);
3610 }
3611 break;
3612 case kBottomSide:
3613 if (y > 0) {
3614 if (IsFixedH(fr)) {
3615 break;
3616 }
3617
3618 w = fr->GetWidth();
3619 h = fr->GetY() + y > (Int_t)hp ? hp - fr->GetY() : UInt_t(y);
3620
3621 //canResize(comp, 0, 0, w, h);
3622 fr->Resize(w, h);
3623 }
3624 break;
3625 case kLeftSide:
3626 if ((int)fr->GetWidth() > x ) {
3627 if (IsFixedW(fr)) {
3628 break;
3629 }
3630
3631 if (fr->GetX() + x < 2) {
3632 x = 2 - fr->GetX();
3633 }
3634 w = fr->GetWidth() - x;
3635 h = fr->GetHeight();
3636 y = fr->GetY();
3637 x = fr->GetX() + x;
3638
3639 //canResize(comp, x, y, w, h);
3640 fr->MoveResize(x, y, w, h);
3641 }
3642 break;
3643 case kRightSide:
3644 if (x > 0) {
3645 if (IsFixedW(fr)) {
3646 break;
3647 }
3648
3649 h = fr->GetHeight();
3650 w = fr->GetX() + x > (Int_t)wp ? wp - fr->GetX() : UInt_t(x);
3651 //canResize(comp, 0, 0, w, h);
3652 fr->Resize(w, h);
3653 }
3654 break;
3655 default:
3656 break;
3657 }
3658 if (comp && (!comp->IsLayoutBroken() || IsFixedLayout(comp))) {
3659 layoutFrame(comp);
3660 }
3661
3662 gVirtualX->SetCursor(fClient->GetRoot()->GetId(),
3663 gVirtualX->CreateCursor(fPimpl->fResizeType));
3664 w = fr->GetWidth();
3665 h = fr->GetHeight();
3666
3667 if (fBuilder) {
3668 TString str = fr->ClassName();
3669 str += "::";
3670 str += fr->GetName();
3671 str += " resized ";
3672 str += TString::Format("(%d x %d)", w, h);
3674 }
3675
3676 fClient->NeedRedraw(fr, kTRUE);
3677 DoRedraw();
3678 fEditor->ChangeSelected(fr); //to update the geometry frame after drag resize
3679}
3680
3681////////////////////////////////////////////////////////////////////////////////
3682/// Handle move
3683
3685{
3686 if (fStop || !fPimpl->fGrab || !fClient->IsEditable()) {
3687 return;
3688 }
3689
3690 TGWindow *parent = (TGWindow*)fPimpl->fGrab->GetParent();
3691
3692 // do not remove frame from fixed layout or non-editable parent
3693 if (IsFixedLayout(parent) || IsEditDisabled(parent)) {
3694 return;
3695 }
3696
3697 Int_t x = fPimpl->fX - fPimpl->fXf;
3698 Int_t y = fPimpl->fY - fPimpl->fYf;
3699
3700 static Int_t qq;
3701 static UInt_t w = 0;
3702 static UInt_t h = 0;
3703
3704 if (w == 0) {
3705 gVirtualX->GetWindowSize(gVirtualX->GetDefaultRootWindow(), qq, qq, w, h);
3706 }
3707
3708 //
3709 Bool_t move = (x > 0) && (y > 0) && ((x + fPimpl->fGrab->GetWidth()) < (w - 0)) &&
3710 ((y + fPimpl->fGrab->GetHeight()) < (h - 30));
3711
3712
3713 // we are out of "win32 world"
3714 if (!move && !gVirtualX->InheritsFrom("TGX11")) {
3715 EndDrag();
3716 return;
3717 }
3718
3719 fPimpl->fGrab->Move(x, y);
3720
3721 if (fBuilder) {
3722 //fBuilder->Update();
3723 TString str = fPimpl->fGrab->ClassName();
3724 str += "::";
3725 str += fPimpl->fGrab->GetName();
3726 str += " is moved to absolute position ";
3727 str += TString::Format("(%d , %d)", x, y);
3729 }
3730
3732}
3733
3734////////////////////////////////////////////////////////////////////////////////
3735/// Return a pointer to the parent mdi frame
3736
3738{
3739 if (fStop || !in) {
3740 return 0;
3741 }
3742
3743 TGFrame *p = in;
3744
3745 while (p && (p != fClient->GetDefaultRoot()) &&
3748 return p;
3749 }
3750 p = (TGFrame*)p->GetParent();
3751 }
3752 return 0;
3753}
3754
3755////////////////////////////////////////////////////////////////////////////////
3756/// Raise guibuilder's mdi frame.
3757
3759{
3760 if (fStop || !comp) {
3761 return;
3762 }
3763
3764 if (comp && comp->InheritsFrom(TGMdiFrame::Class()) && fBuilder) {
3766 if (mdi) {
3767 // dragged frame is taken from some main frame
3768 //if (fPimpl->fGrab && fClient->GetRoot()->InheritsFrom(TGMainFrame::Class())) {
3769 // fBuilder->MapRaised();
3770 //}
3771 }
3772 if (fBuilder->GetMdiMain()->GetCurrent() != comp) {
3774 }
3775 }
3776}
3777
3778////////////////////////////////////////////////////////////////////////////////
3779/// Look for the drop target under grabbed/selected frame while moving
3780
3782{
3783 if (fStop || !fPimpl->fGrab ) {
3784 return;
3785 }
3786
3787 Int_t x = fPimpl->fGrab->GetX();
3788 Int_t y = fPimpl->fGrab->GetY();
3791
3792 Bool_t ok = CheckTargetAtPoint(x - 1, y - 1);
3793
3794 if (!ok) {
3795 ok = CheckTargetAtPoint(x + w + 1, y + h + 1);
3796 }
3797
3798 if (!ok) {
3799 ok = CheckTargetAtPoint(x + w + 1, y - 1);
3800 }
3801
3802 if (!ok) {
3803 CheckTargetAtPoint(x - 1, y + h + 1);
3804 }
3805}
3806
3807////////////////////////////////////////////////////////////////////////////////
3808/// Helper. Look for the drop target under grabbed/selected frame while moving.
3809
3811{
3812 if (fStop || !fPimpl->fGrab) {
3813 return kFALSE;
3814 }
3815
3816 UInt_t ww = fPimpl->fGrab->GetWidth();
3817 UInt_t hh = fPimpl->fGrab->GetHeight();
3818 Bool_t ret = kFALSE;
3819 Window_t c;
3820 TGWindow *win = 0;
3821
3823
3824 if (w && (w != gVirtualX->GetDefaultRootWindow())) {
3826 TGCompositeFrame *comp = 0;
3827
3828 if (!win) {
3829 goto out;
3830 }
3831
3832 if (win->InheritsFrom(TGCompositeFrame::Class())) {
3833 comp = (TGCompositeFrame *)win;
3834 } else if (win->GetParent() != fClient->GetDefaultRoot()) {
3835 comp = (TGCompositeFrame *)win->GetParent();
3836 }
3837
3838 if (comp) {
3839 gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(),
3840 comp->GetId(), x, y, x, y, c);
3841
3842 RaiseMdiFrame(comp);
3843
3844 if ((comp != fPimpl->fGrab) && (x >= 0) && (y >= 0) &&
3845 (x + ww <= comp->GetWidth()) &&
3846 (y + hh <= comp->GetHeight())) {
3847
3848 if (comp != fTarget) {
3850
3852
3853 else Snap2Grid();
3854 } else {
3855 if (fTarget) {
3857 }
3858 }
3859
3860 fTarget = comp;
3861 fTargetId = comp->GetId();
3862 ret = kTRUE;
3863 return ret;
3864
3865 } else {
3866 if (fTarget) {
3868 }
3869 fTarget = 0;
3870 fTargetId = 0;
3871 }
3872 }
3873 }
3874
3875out:
3876 if (fTarget) {
3878 }
3879
3880 if (!w || !win) {
3881 fTarget = 0;
3882 fTargetId = 0;
3883 }
3884 return ret;
3885}
3886
3887////////////////////////////////////////////////////////////////////////////////
3888/// Handle motion event
3889
3891{
3892 if (fStop) {
3893 return kFALSE;
3894 }
3895
3896 static Long64_t was = gSystem->Now();
3897 static Int_t gy = event->fYRoot;
3898 static Int_t gx = event->fXRoot;
3899
3900 Long64_t now = gSystem->Now();
3901
3902 if ((now-was < 100) || !(event->fState & kButton1Mask) ||
3903 ((event->fYRoot == gy) && (event->fXRoot == gx))) {
3904 return kFALSE;
3905 }
3906
3907 was = now;
3908 gy = event->fYRoot;
3909 gx = event->fXRoot;
3910
3911 if (!fDragging) {
3912 if (fMoveWaiting && ((TMath::Abs(fPimpl->fX - event->fXRoot) > 10) ||
3913 (TMath::Abs(fPimpl->fY - event->fYRoot) > 10))) {
3914
3915 return StartDrag(fSource, event->fXRoot, event->fYRoot);
3916 }
3917 } else {
3918 fPimpl->fX = event->fXRoot;
3919 fPimpl->fY = event->fYRoot;
3920
3921 switch (fDragType) {
3922 case kDragLasso:
3923 DrawLasso();
3924 fSelectionIsOn = event->fState & kKeyShiftMask;
3925 break;
3926 case kDragMove:
3927 case kDragCopy:
3928 case kDragLink:
3929 DoMove();
3930 break;
3931 case kDragResize:
3932 DoResize();
3933 break;
3934 default:
3935 break;
3936 }
3937 }
3939 return kTRUE;
3940}
3941
3942////////////////////////////////////////////////////////////////////////////////
3943/// Put created frame at position of the last mouse click
3944
3946{
3947 Int_t x0, y0, x, y;
3948 Window_t c;
3949
3950 if (fStop || !frame || !fClient->IsEditable()) {
3951 return;
3952 }
3953
3954 frame->MapSubwindows();
3955 TGFrame *root = (TGFrame*)fClient->GetRoot();
3956
3957 gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(),
3958 root->GetId(),
3959 fPimpl->fX0 , fPimpl->fY0, x0, y0, c);
3960 gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(),
3961 root->GetId(),
3962 fPimpl->fX , fPimpl->fY, x, y, c);
3963
3964 ToGrid(x, y);
3965 ToGrid(x0, y0);
3966
3967 UInt_t w = TMath::Abs(x - x0);
3968 UInt_t h = TMath::Abs(y - y0);
3969 x = x > x0 ? x0 : x;
3970 y = y > y0 ? y0 : y;
3971
3972 // do not create frame with size smaller when default size
3973 w = w < frame->GetDefaultWidth() + 2 ? frame->GetDefaultWidth() + 2 : w;
3974 h = h < frame->GetDefaultHeight() + 2 ? frame->GetDefaultHeight() + 2 : h;
3975
3976 // do not create frame out of editable space
3977 x = x + w > root->GetWidth() ? Int_t(root->GetWidth() - w) : x;
3978 y = y + h > root->GetHeight() ? Int_t(root->GetHeight() - h) : y;
3979
3980 frame->Move(x, y);
3981
3982 UInt_t grid = GetGridStep();
3983
3984 if (IsFixedW(frame) || IsFixedH(frame) || IsFixedSize(frame)) {
3985 w = IsFixedW(frame) ? frame->GetDefaultWidth() : w;
3986 h = IsFixedH(frame) ? frame->GetDefaultHeight() : h;
3987 frame->Resize(w < grid ? grid : w, h < grid ? grid : h);
3988 } else {
3989 if (frame->InheritsFrom(TGVerticalFrame::Class())) {
3990 frame->Resize(w < grid ? 15*grid : w, h < grid ? 30*grid : h);
3991 } else if (frame->InheritsFrom(TGHorizontalFrame::Class())) {
3992 frame->Resize(w < grid ? 30*grid : w, h < grid ? 15*grid : h);
3993 }
3994 else frame->Resize(w < 2*grid ? 2*grid : w, h < 2*grid ? 2*grid : h);
3995 }
3996
3997 frame->MapRaised();
3998 frame->SetCleanup(kDeepCleanup);
3999 frame->AddInput(kButtonPressMask);
4000
4003 edit->SetCleanup(kDeepCleanup);
4004 ReparentFrames(frame, edit);
4005 frame->MapRaised();
4006 //edit->SetLayoutBroken();
4007 UInt_t g = 2;
4008 // temporary hack for status bar
4009 if (frame->InheritsFrom("TGStatusBar")) {
4011 }
4012 else {
4013 edit->AddFrame(frame, hints ? hints : new TGLayoutHints(kLHintsNormal, g, g, g, g));
4014 }
4015
4016 if (hints && !edit->IsLayoutBroken()) {
4017 edit->GetLayoutManager()->Layout();
4018 } else {
4019 edit->Layout();
4020 }
4021 }
4022 if (fBuilder) {
4023 TString str = frame->ClassName();
4024 str += "::";
4025 str += frame->GetName();
4026 str += " created";
4028 }
4029
4030 if (frame->InheritsFrom(TGCanvas::Class())) {
4031 frame = ((TGCanvas*)frame)->GetContainer();
4032 }
4033
4034 SelectFrame(frame);
4035
4036}
4037////////////////////////////////////////////////////////////////////////////////
4038/// Draw lasso for allocation new object
4039
4041{
4042 if (fStop || !fClient->IsEditable()) {
4043 return;
4044 }
4045
4046 UngrabFrame();
4047
4048 Int_t x0, y0, x, y;
4049 Window_t c;
4050 TGFrame *root = (TGFrame*)fClient->GetRoot();
4051
4052 gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(), root->GetId(),
4053 fPimpl->fX0 , fPimpl->fY0, x0, y0, c);
4054 gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(), root->GetId(),
4055 fPimpl->fX , fPimpl->fY, x, y, c);
4056
4057 UInt_t w, h;
4058 Bool_t xswap = kFALSE;
4059 Bool_t yswap = kFALSE;
4060
4061 // check limits
4062
4063 if ((x == x0) || ( y==y0 )) return; //lasso is not rectangle -> do not draw it
4064
4065 if (x > x0) {
4066 x0 = x0 < 0 ? 0 : x0;
4067 w = x - x0;
4068 } else {
4069 x = x < 0 ? 0 : x;
4070 w = x0 - x;
4071 x0 = x;
4072 xswap = kTRUE;
4073 }
4074
4075 if (y > y0) {
4076 y0 = y0 < 0 ? 0 : y0;
4077 h = y - y0;
4078 } else {
4079 y = y < 0 ? 0 : y;
4080 h = y0 - y;
4081 y0 = y;
4082 yswap = kTRUE;
4083 }
4084
4085 w = x0 + w > root->GetWidth() ? root->GetWidth() - x0 : w;
4086 h = y0 + h > root->GetHeight() ? root->GetHeight() - y0 : h;
4087 x = x0 + w;
4088 y = y0 + h;
4089
4090 ToGrid(x, y);
4091 ToGrid(x0, y0);
4092
4093 // correct fPimpl->fX0 , fPimpl->fY0 , fPimpl->fX , fPimpl->fY
4094 gVirtualX->TranslateCoordinates(root->GetId(), fClient->GetDefaultRoot()->GetId(),
4095 xswap ? x : x0, yswap ? y : y0,
4096 fPimpl->fX0 , fPimpl->fY0, c);
4097 gVirtualX->TranslateCoordinates(root->GetId(), fClient->GetDefaultRoot()->GetId(),
4098 xswap ? x0 : x, yswap ? y0 : y,
4099 fPimpl->fX , fPimpl->fY, c);
4100 DoRedraw();
4101
4102 gVirtualX->DrawRectangle(fClient->GetRoot()->GetId(),
4103 GetBlackGC()(), x0, y0, w, h);
4104 gVirtualX->DrawRectangle(fClient->GetRoot()->GetId(),
4105 GetBlackGC()(), x0+1, y0+1, w-2, h-2);
4106
4107 gVirtualX->SetCursor(fId, gVirtualX->CreateCursor(kCross));
4108 gVirtualX->SetCursor(fClient->GetRoot()->GetId(), gVirtualX->CreateCursor(kCross));
4109
4111 root->RequestFocus();
4112
4113 if (fBuilder) {
4114 TString str = "Lasso drawn. Align frames inside or press Return key to grab frames.";
4116 }
4117}
4118
4119////////////////////////////////////////////////////////////////////////////////
4120/// Handle client message
4121
4123{
4124 if (fStop) {
4125 return kFALSE;
4126 }
4127
4128 if ((event->fFormat == 32) && ((Atom_t)event->fUser[0] == gWM_DELETE_WINDOW) &&
4129 (event->fHandle != gROOT_MESSAGE)) {
4130
4131 if (fPimpl->fPlane && (fPimpl->fPlane->GetId() == event->fWindow)) {
4132 fPimpl->fPlane = 0;
4133 }
4134
4135 TGWindow *root = (TGWindow*)fClient->GetRoot();
4136 if (!root || (root == fClient->GetDefaultRoot())) {
4138 return kTRUE;
4139 }
4141
4142 if (event->fWindow == main->GetId()) {
4143 if (main != fBuilder) {
4144 if (fEditor && !fEditor->IsEmbedded()) {
4145 delete fEditor;
4146 fEditor = 0;
4147 }
4148
4150 return kTRUE;
4151 }
4152
4153 delete fFrameMenu;
4154 fFrameMenu =0;
4155
4156 delete fLassoMenu;
4157 fLassoMenu = 0;
4158
4159 delete fPimpl->fGrid;
4160 fPimpl->fGrid = 0;
4161 Reset1();
4162
4163 } else if (fBuilder && (event->fWindow == fBuilder->GetId())) {
4165
4166 } else if (fEditor && (event->fWindow == fEditor->GetMainFrame()->GetId())) {
4168 fEditor = 0;
4169 }
4170
4171 // to avoid segv. stop editting
4173 }
4174
4175 return kFALSE;
4176}
4177
4178////////////////////////////////////////////////////////////////////////////////
4179/// Handle destroy notify
4180
4182{
4183 if (fPimpl->fPlane && (fPimpl->fPlane->GetId() == event->fWindow)) {
4184 fPimpl->fPlane = 0;
4185 }
4186
4187 return kFALSE;
4188}
4189
4190
4191////////////////////////////////////////////////////////////////////////////////
4192/// not used yet.
4193
4195{
4196 if (fStop) {
4197 return kFALSE;
4198 }
4199
4200 return kFALSE;
4201}
4202
4203////////////////////////////////////////////////////////////////////////////////
4204/// not used yet.
4205
4207{
4208 if (fStop) {
4209 return kFALSE;
4210 }
4211
4212 return kFALSE;
4213}
4214
4215////////////////////////////////////////////////////////////////////////////////
4216/// Find parent frame which can be dragged
4217
4219{
4220 if (fStop) {
4221 return 0;
4222 }
4223
4224 TGFrame *ret = (TGFrame*)p;
4225 TGWindow *parent = (TGWindow*)ret->GetParent();
4226
4227 while (parent && (parent != fClient->GetDefaultRoot())) {
4228 if (!IsFixedLayout(parent) && !IsEditDisabled(parent)) {
4229 return ret;
4230 }
4231 ret = (TGFrame*)parent;
4232 parent = (TGWindow*)ret->GetParent();
4233 }
4234
4235 return 0;
4236}
4237
4238////////////////////////////////////////////////////////////////////////////////
4239/// Find parent frame which can be resized
4240
4242{
4243 if (fStop) {
4244 return 0;
4245 }
4246
4247 TGWindow *parent = p;
4248
4249 while (parent && (parent != fClient->GetDefaultRoot())) {
4250 if (!IsFixedSize(parent) &&
4251 !IsFixedLayout((TGWindow*)parent->GetParent()) &&
4252 !IsEditDisabled((TGWindow*)parent->GetParent())) {
4253 return parent;
4254 }
4255 parent = (TGWindow*)parent->GetParent();
4256 }
4257
4258 return 0;
4259}
4260
4261////////////////////////////////////////////////////////////////////////////////
4262/// Start dragging.
4263
4265{
4266 if (fStop || fDragging) {
4267 return kFALSE;
4268 }
4269
4270 TGFrame *mov = src;
4271
4272 // special case when frame was grabbed via spacebar pressing
4274 if (fDragType == kDragNone) {
4277 } else {
4279 }
4280 }
4281
4282 TGWindow *parent = (TGWindow*)(mov ? mov->GetParent() : 0);
4283
4284 // do not remove frame from fixed layout or non-editable parent
4285 // try to drag "draggable parent"
4286 if (parent && (IsFixedLayout(parent) || IsEditDisabled(parent))) {
4287 mov = GetMovableParent(parent);
4288 if (!mov) {
4289 return kFALSE;
4290 }
4291 }
4292
4293 SetEditable(kTRUE); // grab server
4294
4295 fPimpl->fX = x;
4296 fPimpl->fY = y;
4298
4301
4303 fDragging = kTRUE;
4304 if (src) gVirtualX->SetCursor(src->GetId(), gVirtualX->CreateCursor(kMove));
4305
4306 switch (fDragType) {
4307 case kDragCopy:
4308 HandleCopy();
4309 HandlePaste();
4311 break;
4312 case kDragMove:
4313 fPimpl->fGrab = mov;
4315 break;
4316 default:
4317 //fPimpl->fGrab = 0;
4318 break;
4319 }
4320
4321 return kTRUE;
4322}
4323
4324////////////////////////////////////////////////////////////////////////////////
4325/// End dragging.
4326
4328{
4329 TGFrame *frame = 0;
4330 Bool_t ret = kFALSE;
4331
4332 if (fStop) {
4333 return kFALSE;
4334 }
4335
4336 fMoveWaiting = kFALSE; // for sanity check
4337
4338 if (fPimpl->fGrab && (fDragType >= kDragMove) && (fDragType <= kDragLink)) {
4339
4340 ret = Drop();
4341
4342 } else if (fBuilder && fBuilder->IsExecutable() &&
4344
4345 frame = (TGFrame*)fBuilder->ExecuteAction();
4346 PlaceFrame(frame, fBuilder->GetAction()->fHints);