63 ClassImp(TGuiBldDragManager);
 
   65 static UInt_t gGridStep = 8;
 
   66 static TGuiBldDragManager *gGuiBldDragManager = 0;
 
   67 TGColorDialog *TGuiBldDragManager::fgGlobalColorDialog = 0;
 
   68 TGFontDialog *TGuiBldDragManager::fgGlobalFontDialog = 0;
 
   70 static const char *gSaveMacroTypes[] = {
 
   76 static const char *gImageTypes[] = {
 
   91    "Enacapsulated PostScript", 
"*.eps",
 
   94    "ASImage XML",
"*.xml",
 
  102 class TGuiBldMenuDialog : 
public TGTransientFrame {
 
  104 friend class TGuiBldDragManager;
 
  117    virtual ~TGuiBldMenuDialog();
 
  118    TGuiBldMenuDialog(
const TGWindow *main, TObject *obj, TMethod *method);
 
  120    const char *GetParameters();
 
  122    void ConnectButtonSignals();
 
  126    void Add(
const char *argname, 
const char *value, 
const char *type);
 
  130 static TGuiBldMenuDialog *gMenuDialog = 0;
 
  136 TGuiBldMenuDialog::TGuiBldMenuDialog(
const TGWindow *main, TObject *obj, TMethod *method) :
 
  137     TGTransientFrame(gClient->GetDefaultRoot(), main, 200, 100)
 
  143    fWidgets = 
new TList();
 
  145    fL1 = 
new TGLayoutHints(kLHintsTop | kLHintsCenterX, 0, 0, 5, 0);
 
  146    fL2 = 
new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
 
  148    TString title = obj->ClassName();
 
  150    title += method->GetName();
 
  153    ConnectButtonSignals();
 
  155    SetWindowName(title);
 
  157    SetEditDisabled(kEditDisable);
 
  165 TGuiBldMenuDialog::~TGuiBldMenuDialog()
 
  176 void TGuiBldMenuDialog::ConnectButtonSignals()
 
  178    fOK->Connect(
"Pressed()", 
"TGuiBldDragManager", gGuiBldDragManager, 
"DoDialogOK()");
 
  180    fCancel->Connect(
"Pressed()", 
"TGuiBldDragManager", gGuiBldDragManager, 
"DoDialogCancel()");
 
  186 void TGuiBldMenuDialog::ApplyMethod()
 
  188    const char *params = GetParameters();
 
  189    fObject->Execute(fMethod->GetName(), params);
 
  195 const char *TGuiBldMenuDialog::GetParameters()
 
  197    static char params[1024];
 
  210    TIter next(fWidgets);
 
  213    while ((obj = next())) {        
 
  214       if (obj->IsA() != TGLabel::Class()) 
break;
 
  216       str = (TObjString *) next(); 
 
  220       const char *type = str->GetString().Data();
 
  221       const char *data = 0;
 
  223       if (obj->IsA() == TGTextEntry::Class())
 
  224          data = ((TGTextEntry *) obj)->GetBuffer()->GetString();
 
  229       if (selfobjpos == nparam-1) {
 
  230          if (params[0]) strlcat(params, 
",", 1024-strlen(params));
 
  231          snprintf(param, 255, 
"(TObject*)0x%lx", (Long_t)fObject);
 
  232          strlcat(params, param, 1024-strlen(params));
 
  235       if (params[0]) strlcat(params, 
",", 1024-strlen(params));
 
  237          if (!strncmp(type, 
"char*", 5))
 
  238             snprintf(param, 255, 
"\"%s\"", data);
 
  240             strlcpy(param, data, 
sizeof(param));
 
  242          strlcpy(param, 
"0", 
sizeof(param));
 
  244       strlcat(params, param, 1024-strlen(params));
 
  248    if (selfobjpos == nparam) {
 
  249       if (params[0]) strlcat(params, 
",", 1024-strlen(params));
 
  250       snprintf(param, 255, 
"(TObject*)0x%lx", (Long_t)fObject);
 
  251       strlcat(params, param, 1024-strlen(params));
 
  260 static TString CreateArgumentTitle(TMethodArg *argument)
 
  265       ret.Form(
"(%s)  %s", argument->GetTitle(), argument->GetName());
 
  266       if (argument->GetDefault() && *(argument->GetDefault())) {
 
  267          ret += 
"  [default: ";
 
  268          ret += argument->GetDefault();
 
  279 void TGuiBldMenuDialog::Add(
const char *argname, 
const char *value, 
const char *type)
 
  281    TGLabel      *l = 
new TGLabel(
this, argname);
 
  282    TGTextBuffer *b = 
new TGTextBuffer(20);
 
  283    b->AddText(0, value);
 
  284    TGTextEntry  *t = 
new TGTextEntry(
this, b);
 
  286    t->Connect(
"ReturnPressed()", 
"TGuiBldDragManager", gGuiBldDragManager, 
"DoDialogOK()");
 
  287    t->Resize(260, t->GetDefaultHeight());
 
  293    fWidgets->Add(
new TObjString(type));
 
  299 void TGuiBldMenuDialog::CloseWindow()
 
  301    gGuiBldDragManager->DoDialogCancel();
 
  307 void TGuiBldMenuDialog::Build()
 
  309    TMethodArg *argument = 0;
 
  310    Int_t selfobjpos = -1;
 
  312    TIter next(fMethod->GetListOfMethodArgs());
 
  315    while ((argument = (TMethodArg *) next())) {
 
  317       if (selfobjpos != argpos) {
 
  318          TString arg_name = CreateArgumentTitle(argument);
 
  319          const char *argname = arg_name.Data();
 
  320          const char *type = argument->GetTypeName();
 
  321          TDataType  *datatype = gROOT->GetType(type);
 
  322          const char *charstar = 
"char*";
 
  326             strlcpy(basictype, datatype->GetTypeName(), 
sizeof(basictype));
 
  328             TClass *cl = TClass::GetClass(type);
 
  329             if (strncmp(type, 
"enum", 4) && (cl && !(cl->Property() & kIsEnum)))
 
  330                Warning(
"Dialog", 
"data type is not basic type, assuming (int)");
 
  331             strlcpy(basictype, 
"int", 
sizeof(basictype));
 
  334          if (strchr(argname, 
'*')) {
 
  335             strlcat(basictype, 
"*", 32-strlen(basictype));
 
  339          TDataMember *m = argument->GetDataMember();
 
  340          if (m && m->GetterMethod(fObject->IsA())) {
 
  345             if (!strncmp(basictype, 
"char*", 5)) {
 
  347                m->GetterMethod()->Execute(fObject, 
"", &tdefval);
 
  348                if (tdefval && strlen(tdefval))
 
  349                   strlcpy(val, tdefval, 
sizeof(val));
 
  350             } 
else if (!strncmp(basictype, 
"float", 5) ||
 
  351                        !strncmp(basictype, 
"double", 6)) {
 
  352                Double_t ddefval = 0.0;
 
  353                m->GetterMethod()->Execute(fObject, 
"", ddefval);
 
  354                snprintf(val, 255, 
"%g", ddefval);
 
  355             } 
else if (!strncmp(basictype, 
"char", 4) ||
 
  356                        !strncmp(basictype, 
"bool", 4) ||
 
  357                        !strncmp(basictype, 
"int", 3)  ||
 
  358                        !strncmp(basictype, 
"long", 4) ||
 
  359                        !strncmp(basictype, 
"short", 5)) {
 
  361                m->GetterMethod()->Execute(fObject, 
"", ldefval);
 
  362                snprintf(val, 255, 
"%li", ldefval);
 
  369             if ((opt = m->GetOptions())) {
 
  370                Warning(
"Dialog", 
"option menu not yet implemented");
 
  374                Add(argname, val, type);
 
  379             const char *tval = argument->GetDefault();
 
  380             if (tval) strlcpy(val, tval, 
sizeof(val));
 
  381             Add(argname, val, type);
 
  388    TGHorizontalFrame *hf = 
new TGHorizontalFrame(
this, 60, 20, kFixedWidth);
 
  389    TGLayoutHints     *l1 = 
new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 5, 5, 0, 0);
 
  390    UInt_t  width = 0, height = 0;
 
  394    fOK = 
new TGTextButton(hf, 
"&OK", 1);
 
  395    hf->AddFrame(fOK, l1);
 
  397    height = fOK->GetDefaultHeight();
 
  398    width  = TMath::Max(width, fOK->GetDefaultWidth());
 
  408    fCancel = 
new TGTextButton(hf, 
"&Cancel", 3);
 
  409    hf->AddFrame(fCancel, l1);
 
  410    fWidgets->Add(fCancel);
 
  411    height = fCancel->GetDefaultHeight();
 
  412    width  = TMath::Max(width, fCancel->GetDefaultWidth());
 
  415    l1 = 
new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5);
 
  420    hf->Resize((width + 20) * 3, height);
 
  429 void TGuiBldMenuDialog::Popup()
 
  431    UInt_t width  = GetDefaultWidth();
 
  432    UInt_t height = GetDefaultHeight();
 
  434    Resize(width, height);
 
  437    Int_t x = (Int_t)((TGFrame*)fMain)->GetWidth();
 
  438    Int_t y = (Int_t)((TGFrame*)fMain)->GetHeight();
 
  439    gVirtualX->TranslateCoordinates(fMain->GetId(), fClient->GetDefaultRoot()->GetId(),
 
  446    SetWMSize(width, height);
 
  447    SetWMSizeHints(width, height, width, height, 0, 0);
 
  449    SetMWMHints(kMWMDecorAll | kMWMDecorResizeH  | kMWMDecorMaximize |
 
  450                               kMWMDecorMinimize | kMWMDecorMenu,
 
  451                kMWMFuncAll  | kMWMFuncResize    | kMWMFuncMaximize |
 
  458    fClient->WaitFor(
this);
 
  466 static Window_t GetWindowFromPoint(Int_t x, Int_t y)
 
  468    Window_t src, dst, child;
 
  473    if (!gGuiBldDragManager || gGuiBldDragManager->IsStopped() ||
 
  474        !gClient->IsEditable()) 
return 0;
 
  476    dst = src = child = gVirtualX->GetDefaultRootWindow();
 
  478    while (child && dst) {
 
  481       gVirtualX->TranslateCoordinates(src, dst, xx, yy, xx, yy, child);
 
  490 static void layoutFrame(TGFrame *frame)
 
  492    if (!frame || !frame->InheritsFrom(TGCompositeFrame::Class())) {
 
  496    TGCompositeFrame *comp = (TGCompositeFrame*)frame;
 
  498    if (comp->GetLayoutManager()) {
 
  499       comp->GetLayoutManager()->Layout();
 
  503    gClient->NeedRedraw(comp);
 
  505    TIter next(comp->GetList());
 
  508    while ((fe = (TGFrameElement*)next())) {
 
  509       layoutFrame(fe->fFrame);
 
  510       gClient->NeedRedraw(fe->fFrame);
 
  517 static void GuiBldErrorHandler(Int_t , Bool_t ,
 
  518                                  const char * , 
const char * )
 
  523 class TGuiBldDragManagerGrid {
 
  526    static UInt_t   fgStep;
 
  527    static ULong_t  fgPixel;
 
  534    TGuiBldDragManagerGrid();
 
  535    ~TGuiBldDragManagerGrid();
 
  537    void  SetStep(UInt_t step);
 
  542 UInt_t   TGuiBldDragManagerGrid::fgStep = gGridStep;
 
  543 ULong_t  TGuiBldDragManagerGrid::fgPixel = 0;
 
  544 TGGC    *TGuiBldDragManagerGrid::fgBgnd = 0;
 
  549 TGuiBldDragManagerGrid::TGuiBldDragManagerGrid()
 
  564 TGuiBldDragManagerGrid::~TGuiBldDragManagerGrid()
 
  566    fWindow = gClient->GetWindowById(fWinId);
 
  569       fWindow->SetBackgroundPixmap(0);
 
  570       fWindow->SetBackgroundColor(((TGFrame*)fWindow)->GetBackground());
 
  571       gClient->NeedRedraw(fWindow, kTRUE);
 
  574       gVirtualX->DeletePixmap(fPixmap);
 
  585 void TGuiBldDragManagerGrid::SetStep(UInt_t step)
 
  587    if (!gClient || !gClient->IsEditable()) {
 
  591    fWindow = (TGWindow*)gClient->GetRoot();
 
  592    fWinId = fWindow->GetId();
 
  601 void TGuiBldDragManagerGrid::InitBgnd()
 
  607    fgBgnd = 
new TGGC(TGFrame::GetBckgndGC());
 
  615    fgPixel = TColor::RGB2Pixel(r, g, b);
 
  616    fgBgnd->SetForeground(fgPixel);
 
  622 void TGuiBldDragManagerGrid::InitPixmap()
 
  625       gVirtualX->DeletePixmap(fPixmap);
 
  628    fPixmap = gVirtualX->CreatePixmap(gClient->GetDefaultRoot()->GetId(), fgStep, fgStep);
 
  629    gVirtualX->FillRectangle(fPixmap, fgBgnd->GetGC(), 0, 0, fgStep, fgStep);
 
  632       gVirtualX->FillRectangle(fPixmap, TGFrame::GetShadowGC()(),
 
  633                                fgStep - 1, fgStep - 1, 1, 1);
 
  640 void TGuiBldDragManagerGrid::Draw()
 
  642    if (!gClient || !gClient->IsEditable()) {
 
  646    fWindow = gClient->GetWindowById(fWinId);
 
  648    if (fWindow && (fWindow != gClient->GetRoot())) {
 
  649       fWindow->SetBackgroundPixmap(0);
 
  650       fWindow->SetBackgroundColor(((TGFrame*)fWindow)->GetBackground());
 
  651       gClient->NeedRedraw(fWindow);
 
  658    fWindow = (TGWindow*)gClient->GetRoot();
 
  659    fWinId = fWindow->GetId();
 
  660    fWindow->SetBackgroundPixmap(fPixmap);
 
  662    gClient->NeedRedraw(fWindow);
 
  667 class TGuiBldDragManagerRepeatTimer : 
public TTimer {
 
  670    TGuiBldDragManager *fManager;   
 
  673    TGuiBldDragManagerRepeatTimer(TGuiBldDragManager *m, Long_t ms) :
 
  674                                  TTimer(ms, kTRUE) { fManager = m; }
 
  675    Bool_t Notify() { fManager->HandleTimer(
this); Reset(); 
return kFALSE; }
 
  680 class TGGrabRect : 
public TGFrame {
 
  687    TGGrabRect(Int_t type);
 
  690    Bool_t HandleButton(Event_t *ev);
 
  691    ECursor GetType()
 const { 
return fType; }
 
  697 TGGrabRect::TGGrabRect(Int_t type) :
 
  698       TGFrame(gClient->GetDefaultRoot(), 8, 8, kTempFrame)
 
  725          fType = kBottomRight;
 
  729    SetWindowAttributes_t attr;
 
  730    attr.fMask             = kWAOverrideRedirect | kWASaveUnder;
 
  731    attr.fOverrideRedirect = kTRUE;
 
  732    attr.fSaveUnder        = kTRUE;
 
  734    gVirtualX->ChangeWindowAttributes(fId, &attr);
 
  736    fPixmap = gVirtualX->CreatePixmap(gVirtualX->GetDefaultRootWindow(), 8, 8);
 
  737    const TGGC *bgc = TRootGuiBuilder::GetPopupHlghtGC();
 
  739    TGGC *gc = 
new TGGC(TGFrame::GetBckgndGC());
 
  742    fClient->GetColorByName(
"black", back);
 
  743    gc->SetBackground(back);
 
  744    gc->SetForeground(back);
 
  746    gVirtualX->FillRectangle(fPixmap, bgc->GetGC(), 0, 0, 7, 7);
 
  747    gVirtualX->DrawRectangle(fPixmap, gc->GetGC(), 0, 0, 7, 7);
 
  750    AddInput(kButtonPressMask);
 
  751    SetBackgroundPixmap(fPixmap);
 
  753    gVirtualX->SetCursor(fId, gVirtualX->CreateCursor(fType));
 
  759 Bool_t TGGrabRect::HandleButton(Event_t *ev)
 
  761    gGuiBldDragManager->CheckDragResize(ev);
 
  766 class TGAroundFrame : 
public TGFrame {
 
  776 TGAroundFrame::TGAroundFrame() : TGFrame(gClient->GetDefaultRoot(), 1, 1,
 
  777                                          kTempFrame | kOwnBackground)
 
  779    SetWindowAttributes_t attr;
 
  780    attr.fMask             = kWAOverrideRedirect | kWASaveUnder;
 
  781    attr.fOverrideRedirect = kTRUE;
 
  782    attr.fSaveUnder        = kTRUE;
 
  784    gVirtualX->ChangeWindowAttributes(fId, &attr);
 
  786    fClient->GetColorByName(
"blue", blue);
 
  787    SetBackgroundColor(blue);
 
  792 class TGuiBldDragManagerPimpl {
 
  794 friend class TGuiBldDragManager;
 
  797    TGuiBldDragManager     *fManager;   
 
  798    TTimer            *fRepeatTimer;    
 
  800    TGLayoutHints     *fGrabLayout;     
 
  802    TGFrame           *fClickFrame;     
 
  803    TGuiBldDragManagerGrid *fGrid;      
 
  808    Int_t              fGrabX, fGrabY;  
 
  809    const TGWindow    *fGrabParent;     
 
  810    Int_t              fLastPopupAction;
 
  812    TGGrabRect        *fGrabRect[8];    
 
  813    TGFrame           *fAroundFrame[4]; 
 
  814    Bool_t             fGrabRectHidden;
 
  815    TGFrameElement    *fGrabListPosition;
 
  816    Bool_t             fButtonPressed;  
 
  819    TGFrame           *fSpacePressedFrame; 
 
  821    TList             *fFrameMenuTrash; 
 
  822    TGFrame           *fMenuObject;     
 
  825    TGuiBldDragManagerPimpl(TGuiBldDragManager *m) {
 
  827       fRepeatTimer = 
new TGuiBldDragManagerRepeatTimer(m, 100);
 
  830       for (i = 0; i <8; i++) {
 
  831          fGrabRect[i] = 
new TGGrabRect(i);
 
  833       for (i = 0; i <4; i++) {
 
  834          fAroundFrame[i] = 
new TGAroundFrame();
 
  837       fFrameMenuTrash = 
new TList();
 
  846       fX0 = fY0 = fX = fY = fXf = fYf = fGrabX = fGrabY = 0;
 
  848       fResizeType = kPointer;
 
  849       fLastPopupAction = kNoneAct;
 
  852       fGrabRectHidden = kFALSE;
 
  853       fGrabListPosition = 0;
 
  854       fButtonPressed = kFALSE;
 
  857       fSpacePressedFrame = 0;
 
  858       fPlacePopup = kFALSE;
 
  859       fFrameMenuTrash->Delete();
 
  863    ~TGuiBldDragManagerPimpl() {
 
  865       for (i = 0; i <8; i++) {
 
  868       for (i = 0; i <4; i++) {
 
  869          delete fAroundFrame[i];
 
  874       fFrameMenuTrash->Delete();
 
  875       delete fFrameMenuTrash;
 
  878          fPlane->ChangeOptions(fPlane->GetOptions() & ~kRaisedFrame);
 
  879          gClient->NeedRedraw(fPlane, kTRUE);
 
  887 TGuiBldDragManager::TGuiBldDragManager() : TVirtualDragManager() ,
 
  888                     TGFrame(gClient->GetDefaultRoot(), 1, 1)
 
  892    SetWindowAttributes_t attr;
 
  893    attr.fMask             = kWAOverrideRedirect | kWASaveUnder;
 
  894    attr.fOverrideRedirect = kTRUE;
 
  895    attr.fSaveUnder        = kTRUE;
 
  897    gVirtualX->ChangeWindowAttributes(fId, &attr);
 
  899    gGuiBldDragManager = 
this;
 
  900    fPimpl = 
new TGuiBldDragManagerPimpl(
this);
 
  902    fSelectionIsOn = kFALSE;
 
  907    fLassoDrawn    = kFALSE;
 
  908    fDropStatus    = kFALSE;
 
  914    CreateListOfDialogs();
 
  916    TString tmpfile = gSystem->TempDirectory();
 
  917    char *s = gSystem->ConcatFileName(tmpfile.Data(),
 
  918                TString::Format(
"RootGuiBldClipboard%d.C", gSystem->GetPid()));
 
  922    s = gSystem->ConcatFileName(tmpfile.Data(),
 
  923                TString::Format(
"RootGuiBldTmpFile%d.C", gSystem->GetPid()));
 
  927    fName = 
"Gui Builder Drag Manager";
 
  928    SetWindowName(fName.Data());
 
  931    SetErrorHandler(GuiBldErrorHandler);
 
  933    fClient->UnregisterWindow(
this);
 
  939 TGuiBldDragManager::~TGuiBldDragManager()
 
  957    if (!gSystem->AccessPathName(fPasteFileName.Data())) {
 
  958       gSystem->Unlink(fPasteFileName.Data());
 
  961    delete fListOfDialogs;
 
  963    gGuiBldDragManager = 0;
 
  969 void TGuiBldDragManager::Reset1()
 
  971    TVirtualDragManager::Init();
 
  973    fPimpl->fPlacePopup = kFALSE;
 
  974    SetCursorType(kPointer);
 
  980 void TGuiBldDragManager::CreateListOfDialogs()
 
  982    fListOfDialogs = 
new TList();
 
  984    TList *methodList = IsA()->GetListOfMethods();
 
  985    TIter next(methodList);
 
  989    while ((method = (TMethod*) next())) {
 
  990       str = method->GetCommentString();
 
  991       if (str.Contains(
"*DIALOG")) {
 
  992          fListOfDialogs->Add(method);
 
 1000 void TGuiBldDragManager::Snap2Grid()
 
 1006    delete fPimpl->fGrid;
 
 1008    fPimpl->fGrid = 
new TGuiBldDragManagerGrid();
 
 1009    fPimpl->fGrid->Draw();
 
 1015 UInt_t TGuiBldDragManager::GetGridStep()
 
 1017    return fPimpl->fGrid ? fPimpl->fGrid->fgStep : 1;
 
 1023 void TGuiBldDragManager::SetGridStep(UInt_t step)
 
 1025    fPimpl->fGrid->SetStep(step);
 
 1031 Bool_t TGuiBldDragManager::IgnoreEvent(Event_t *event)
 
 1033    if (fStop || !fClient || !fClient->IsEditable()) 
return kTRUE;
 
 1034    if (event->fType == kClientMessage) 
return kFALSE;
 
 1035    if (event->fType == kDestroyNotify) 
return kFALSE;
 
 1037    TGWindow *w = fClient->GetWindowById(event->fWindow);
 
 1040       if (IsEditDisabled(w)) {
 
 1041          w = GetEditableParent((TGFrame*)w);
 
 1053 TGFrame* TGuiBldDragManager::InEditable(Window_t 
id)
 
 1059    Window_t preparent = id;
 
 1060    Window_t parent = (Window_t)gVirtualX->GetParent(
id);
 
 1062    while (!parent || (parent != fClient->GetDefaultRoot()->GetId())) {
 
 1063       if (parent == fClient->GetRoot()->GetId()) {
 
 1064          TGWindow *w = fClient->GetWindowById(preparent);
 
 1065          return (w ? (TGFrame*)w : 0);
 
 1068       parent = gVirtualX->GetParent(parent);
 
 1076 TGCompositeFrame *TGuiBldDragManager::FindCompositeFrame(Window_t 
id)
 
 1082    Window_t parent = id;
 
 1084    while (!parent || (parent != fClient->GetDefaultRoot()->GetId())) {
 
 1085       TGWindow *w = fClient->GetWindowById(parent);
 
 1087          if (w->InheritsFrom(TGCompositeFrame::Class())) {
 
 1088             return (TGCompositeFrame*)w;
 
 1091       parent = gVirtualX->GetParent(parent);
 
 1099 void TGuiBldDragManager::SetCursorType(Int_t cur)
 
 1105    static UInt_t gid = 0;
 
 1106    static UInt_t rid = 0;
 
 1108    if (fPimpl->fGrab && (gid != fPimpl->fGrab->GetId())) {
 
 1109       gVirtualX->SetCursor(fPimpl->fGrab->GetId(),
 
 1110                            gVirtualX->CreateCursor((ECursor)cur));
 
 1111       gid = fPimpl->fGrab->GetId();
 
 1113    if (fClient->IsEditable() && (rid != fClient->GetRoot()->GetId())) {
 
 1114       gVirtualX->SetCursor(fClient->GetRoot()->GetId(),
 
 1115                            gVirtualX->CreateCursor((ECursor)cur));
 
 1116       rid = fClient->GetRoot()->GetId();
 
 1123 Bool_t TGuiBldDragManager::CheckDragResize(Event_t *event)
 
 1129    Bool_t ret = kFALSE;
 
 1130    fPimpl->fResizeType = kPointer;
 
 1132    for (
int i = 0; i < 8; i++) {
 
 1133       if (fPimpl->fGrabRect[i]->GetId() == 
event->fWindow) {
 
 1134          fPimpl->fResizeType = fPimpl->fGrabRect[i]->GetType();
 
 1139    if ((event->fType == kButtonPress) && (fPimpl->fResizeType != kPointer)) {
 
 1140       fDragType = kDragResize;
 
 1144    SetCursorType(ret ? fPimpl->fResizeType : kPointer);
 
 1151 void TGuiBldDragManager::DoRedraw()
 
 1153    if (fStop || !fClient || !fClient->IsEditable()) {
 
 1157    TGWindow *root = (TGWindow*)fClient->GetRoot();
 
 1159    fClient->NeedRedraw(root, kTRUE);
 
 1162       fClient->NeedRedraw(fBuilder, kTRUE);
 
 1169 void TGuiBldDragManager::SwitchEditable(TGFrame *frame)
 
 1171    if (fStop || !frame) {
 
 1175    TGCompositeFrame *comp = 0;
 
 1177    if (frame->InheritsFrom(TGCompositeFrame::Class()) && CanChangeLayout(frame)) {
 
 1178       comp = (TGCompositeFrame *)frame;
 
 1179    } 
else if (frame->GetParent()->InheritsFrom(TGCompositeFrame::Class())) {
 
 1180       comp = (TGCompositeFrame *)frame->GetParent();
 
 1187    TString str = comp->ClassName();
 
 1189    str += comp->GetName();
 
 1191    if (IsEditDisabled(comp)) {
 
 1193          str += 
" cannot be editted.";
 
 1194          fBuilder->UpdateStatusBar(str.Data());
 
 1199    if (frame != comp) {
 
 1203    if (comp->IsEditable()) {
 
 1207    RaiseMdiFrame(comp);
 
 1208    comp->SetEditable(kTRUE);
 
 1214 void TGuiBldDragManager::SelectFrame(TGFrame *frame, Bool_t add)
 
 1216    if (fStop || !frame || (frame->GetParent() == fClient->GetDefaultRoot()) ||
 
 1217        !fClient->IsEditable()) {
 
 1221    TString str = frame->ClassName();
 
 1223    str += frame->GetName();
 
 1225    if (IsGrabDisabled(frame)) {
 
 1227          str += 
"can not be selected";
 
 1228          fBuilder->UpdateStatusBar(str.Data());
 
 1234    if (fBuilder && frame->InheritsFrom(TGMdiFrame::Class())) {
 
 1239    static Int_t x, x0, y, y0, xx, yy;
 
 1242    RaiseMdiFrame(FindMdiFrame(frame));
 
 1247       fDragType = (fDragType != kDragCopy ) ?  kDragMove : fDragType;
 
 1249       gVirtualX->TranslateCoordinates(frame->GetId(),
 
 1250                                       fClient->GetDefaultRoot()->GetId(),
 
 1253       x = x0 + frame->GetWidth();
 
 1254       y = y0 + frame->GetHeight();
 
 1258          str += (IsEditDisabled(frame) || IsFixedLayout(frame)  ? 
". This frame cannot be editted." :
 
 1260          str += 
" Press SpaceBar to unselect the frame.";
 
 1261          if (IsFixedSize(frame)) str += 
" This frame cannot be resized.";
 
 1263          fBuilder->UpdateStatusBar(str.Data());
 
 1268       gVirtualX->TranslateCoordinates(frame->GetId(),
 
 1269                                       fClient->GetDefaultRoot()->GetId(),
 
 1272       fDragType = kDragLasso;
 
 1273       fPimpl->fX0 = x0 = TMath::Min(x0, xx);
 
 1274       fPimpl->fX = x = TMath::Max(x, xx + (Int_t)frame->GetWidth());
 
 1275       fPimpl->fY0 = y0 = TMath::Min(y0, yy);
 
 1276       fPimpl->fY = y = TMath::Max(y, yy + (Int_t)frame->GetHeight());
 
 1281    fFrameUnder = fPimpl->fGrab = frame;
 
 1282    fPimpl->fGrab->RequestFocus();
 
 1285    if (frame->InheritsFrom(TGCanvas::Class())) {
 
 1286       fSelected = ((TGCanvas*)frame)->GetContainer();
 
 1288       if (!IsEditDisabled(fSelected)) {
 
 1289          fSelected->SetEditable(kTRUE);
 
 1290          if (fBuilder && fBuilder->GetAction()) {
 
 1291             PlaceFrame((TGFrame*)fBuilder->ExecuteAction(), 0);
 
 1295       fSelected = fPimpl->fGrab;
 
 1297    ChangeSelected(fPimpl->fGrab);
 
 1299    SetCursorType(kMove);
 
 1301    SetLassoDrawn(kFALSE);
 
 1302    DrawGrabRectangles(fPimpl->fGrab);
 
 1308 void TGuiBldDragManager::ChangeSelected(TGFrame *fr)
 
 1316    if (fBuilder && (sel == fBuilder->GetMdiMain()->GetCurrent())) {
 
 1325       fEditor->ChangeSelected(sel);
 
 1329       fBuilder->ChangeSelected(sel);
 
 1337 void TGuiBldDragManager::GrabFrame(TGFrame *frame)
 
 1339    if (fStop || !frame || !fClient->IsEditable()) {
 
 1343    fPimpl->fGrabParent = frame->GetParent();
 
 1344    fPimpl->fGrabX = frame->GetX();
 
 1345    fPimpl->fGrabY = frame->GetY();
 
 1349    gVirtualX->TranslateCoordinates(frame->GetId(),
 
 1350                                    fClient->GetDefaultRoot()->GetId(),
 
 1351                                    0, 0, fPimpl->fX0, fPimpl->fY0, c);
 
 1353    fPimpl->fX = fPimpl->fX0;
 
 1354    fPimpl->fY = fPimpl->fY0;
 
 1356    if (frame->GetFrameElement() && frame->GetFrameElement()->fLayout) {
 
 1357       fPimpl->fGrabLayout = frame->GetFrameElement()->fLayout;
 
 1360    if (fPimpl->fGrabParent && frame->GetFrameElement() &&
 
 1361        fPimpl->fGrabParent->InheritsFrom(TGCompositeFrame::Class())) {
 
 1362       TList *li = ((TGCompositeFrame*)fPimpl->fGrabParent)->GetList();
 
 1363       fPimpl->fGrabListPosition = (TGFrameElement*)li->Before(frame->GetFrameElement());
 
 1364       ((TGCompositeFrame*)fPimpl->fGrabParent)->RemoveFrame(frame);
 
 1367    SetWindowAttributes_t attr;
 
 1368    attr.fMask             = kWAOverrideRedirect | kWASaveUnder;
 
 1369    attr.fOverrideRedirect = kTRUE;
 
 1370    attr.fSaveUnder        = kTRUE;
 
 1372    gVirtualX->ChangeWindowAttributes(frame->GetId(), &attr);
 
 1374    frame->UnmapWindow();
 
 1375    frame->ReparentWindow(fClient->GetDefaultRoot(), fPimpl->fX0, fPimpl->fY0);
 
 1376    gVirtualX->Update(1);
 
 1377    frame->Move(fPimpl->fX0, fPimpl->fY0);
 
 1382       TString str = frame->ClassName();
 
 1384       str += frame->GetName();
 
 1385       str += 
" is grabbed";
 
 1387       fBuilder->UpdateStatusBar(str.Data());
 
 1394 void TGuiBldDragManager::UngrabFrame()
 
 1396    if (fStop || !fPimpl->fGrab) {
 
 1400    SetCursorType(kPointer);
 
 1401    HideGrabRectangles();
 
 1407       TString str = fPimpl->fGrab->ClassName();
 
 1409       str += fPimpl->fGrab->GetName();
 
 1410       str += 
" ungrabbed";
 
 1411       fBuilder->UpdateStatusBar(str.Data());
 
 1413    fSelected = fPimpl->fGrab = 0;
 
 1419 static Bool_t IsParentOfGrab(Window_t 
id, 
const TGWindow *grab)
 
 1421    const TGWindow *parent = grab;
 
 1423    while (parent && (parent != gClient->GetDefaultRoot())) {
 
 1424       if (parent->GetId() == id) {
 
 1427       parent = parent->GetParent();
 
 1436 Bool_t TGuiBldDragManager::IsPointVisible(Int_t xi, Int_t yi)
 
 1438    Window_t w = gVirtualX->GetDefaultRootWindow();
 
 1439    Window_t src, dst, child;
 
 1442    Bool_t ret = kFALSE;
 
 1444    gVirtualX->TranslateCoordinates(fPimpl->fGrab->GetId(), w, x, y, x, y, child);
 
 1446    dst = src = child = w;
 
 1451       gVirtualX->TranslateCoordinates(src, dst, x, y, x, y, child);
 
 1453       if (IsParentOfGrab(child, fPimpl->fGrab)) {
 
 1464 Bool_t TGuiBldDragManager::IsSelectedVisible()
 
 1466    if (fStop || !fPimpl->fGrab || !fClient->IsEditable()) {
 
 1471       TGMdiFrame *mdi = fBuilder->FindEditableMdiFrame(fPimpl->fGrab);
 
 1472       if (mdi && (mdi != fBuilder->GetMdiMain()->GetCurrent())) {
 
 1478    if (fPimpl->fPlacePopup) {
 
 1482    static Long64_t was = gSystem->Now();
 
 1483    static Bool_t visible = kFALSE;
 
 1485    Long64_t now = gSystem->Now();
 
 1487    if (now-was < 100) {
 
 1494    if (!IsPointVisible(2, 2)) {
 
 1498    if (!IsPointVisible(2, fPimpl->fGrab->GetHeight()-2)) {
 
 1502    if (!IsPointVisible(fPimpl->fGrab->GetWidth()-2, 2)) {
 
 1506    if (!IsPointVisible(fPimpl->fGrab->GetWidth()-2,
 
 1507                        fPimpl->fGrab->GetHeight()-2)) {
 
 1519 void TGuiBldDragManager::DrawGrabRectangles(TGWindow *win)
 
 1525    TGFrame *frame = win ? (TGFrame *)win : fPimpl->fGrab;
 
 1527    if (!frame || !fClient->IsEditable() || fPimpl->fPlacePopup) {
 
 1531    Window_t w = gVirtualX->GetDefaultRootWindow();
 
 1532    Window_t c; Int_t x, y;
 
 1534    gVirtualX->TranslateCoordinates(frame->GetId(), w,  0, 0, x, y, c);
 
 1536    if (frame->InheritsFrom(TGCompositeFrame::Class()) &&
 
 1537        CanChangeLayout(frame) && !frame->IsLayoutBroken()) {
 
 1538       fPimpl->fAroundFrame[0]->MoveResize(x-3, y-3, frame->GetWidth()+6, 2);
 
 1539       fPimpl->fAroundFrame[0]->MapRaised();
 
 1540       fPimpl->fAroundFrame[1]->MoveResize(x+frame->GetWidth()+3, y-3, 2, frame->GetHeight()+6);
 
 1541       fPimpl->fAroundFrame[1]->MapRaised();
 
 1542       fPimpl->fAroundFrame[2]->MoveResize(x-3, y+frame->GetHeight()+2, frame->GetWidth()+6, 2);
 
 1543       fPimpl->fAroundFrame[2]->MapRaised();
 
 1544       fPimpl->fAroundFrame[3]->MoveResize(x-3, y-3, 2, frame->GetHeight()+6);
 
 1545       fPimpl->fAroundFrame[3]->MapRaised();
 
 1547       for (
int i = 0; i < 4; i++) fPimpl->fAroundFrame[i]->UnmapWindow();
 
 1551    DrawGrabRect(0, x - 6, y - 6);
 
 1552    DrawGrabRect(1, x + frame->GetWidth()/2 - 3, y - 6);
 
 1553    DrawGrabRect(2, x + frame->GetWidth(), y - 6);
 
 1554    DrawGrabRect(3, x - 6, y + frame->GetHeight());
 
 1555    DrawGrabRect(4, x - 6, y + frame->GetHeight()/2 - 3);
 
 1556    DrawGrabRect(5, x + frame->GetWidth(), y + frame->GetHeight()/2 - 3);
 
 1557    DrawGrabRect(6, x + frame->GetWidth()/2 - 3, y + frame->GetHeight());
 
 1558    DrawGrabRect(7, x + frame->GetWidth(), y + frame->GetHeight());
 
 1560    fPimpl->fGrabRectHidden = kFALSE;
 
 1566 void TGuiBldDragManager::DrawGrabRect(Int_t i, Int_t x, Int_t y)
 
 1572    fPimpl->fGrabRect[i]->Move(x, y);
 
 1573    fPimpl->fGrabRect[i]->MapRaised();
 
 1580 void TGuiBldDragManager::HighlightCompositeFrame(Window_t win)
 
 1582    static Window_t gw = 0;
 
 1584    if (fStop || !win || (win == gw)) {
 
 1588    TGWindow *w = fClient->GetWindowById(win);
 
 1590    if (!w || (w == fPimpl->fPlane) || w->GetEditDisabled() || w->IsEditable() ||
 
 1591        !w->InheritsFrom(TGCompositeFrame::Class())) {
 
 1595    TGFrame *frame = (TGFrame*)w;
 
 1596    UInt_t opt = frame->GetOptions();
 
 1598    if ((opt & kRaisedFrame) || (opt & kSunkenFrame)) {
 
 1603    if (fPimpl->fPlane) {
 
 1604       fPimpl->fPlane->ChangeOptions(fPimpl->fPlane->GetOptions() & ~kRaisedFrame);
 
 1605       fClient->NeedRedraw(fPimpl->fPlane, kTRUE);
 
 1607    fPimpl->fPlane = frame;
 
 1608    fPimpl->fPlane->ChangeOptions(opt | kRaisedFrame);
 
 1609    fClient->NeedRedraw(fPimpl->fPlane, kTRUE);
 
 1612       TString str = frame->ClassName();
 
 1614       str += frame->GetName();
 
 1615       fBuilder->UpdateStatusBar(str.Data());
 
 1624 Bool_t TGuiBldDragManager::HandleTimer(TTimer *t)
 
 1626    return HandleTimerEvent(0, t);
 
 1632 Bool_t TGuiBldDragManager::HandleTimerEvent(Event_t *e, TTimer *t)
 
 1634    static Int_t gy = 0;
 
 1635    static Int_t gx = 0;
 
 1636    static UInt_t gstate = 0;
 
 1637    static Window_t gw = 0;
 
 1642    if (!fClient || !fClient->IsEditable()) {
 
 1643       SetEditable(kFALSE);
 
 1646    if (!IsSelectedVisible()) {
 
 1647       HideGrabRectangles();
 
 1650       if (fPimpl->fRepeatTimer) {
 
 1652          fPimpl->fRepeatTimer->Reset();
 
 1653          fPimpl->fRepeatTimer->Remove();
 
 1655       if (e->fType == kButtonPress)
 
 1656          return HandleButtonPress(e);
 
 1657       else if (e->fType == kButtonRelease)
 
 1658          return HandleButtonRelease(e);
 
 1659       else if (e->fState & kButton1Mask)
 
 1660          return HandleMotion(e);
 
 1665    ev.fCode = kButton1;
 
 1666    ev.fType = kMotionNotify;
 
 1669    gVirtualX->QueryPointer(gVirtualX->GetDefaultRootWindow(), dum, dum,
 
 1670                            ev.fXRoot, ev.fYRoot, ev.fX, ev.fY, ev.fState);
 
 1672    ev.fWindow = GetWindowFromPoint(ev.fXRoot, ev.fYRoot);
 
 1674    if (ev.fWindow && (gw == ev.fWindow) && (gstate == ev.fState) &&
 
 1675        (ev.fYRoot == gy) && (ev.fXRoot == gx)) {
 
 1684    if (!fDragging && !fMoveWaiting && !fPimpl->fButtonPressed &&
 
 1685        ((ev.fState == kButton1Mask) || (ev.fState == kButton3Mask) ||
 
 1686         (ev.fState == (kButton1Mask | kKeyShiftMask)) ||
 
 1687         (ev.fState == (kButton1Mask | kKeyControlMask)))) {
 
 1689       if (ev.fState & kButton1Mask) ev.fCode = kButton1;
 
 1690       if (ev.fState & kButton3Mask) ev.fCode = kButton3;
 
 1692       ev.fType = kButtonPress;
 
 1695       if (fPimpl->fPlane && fClient->GetWindowById(fPimpl->fPlane->GetId())) {
 
 1696          fPimpl->fPlane->ChangeOptions(fPimpl->fPlane->GetOptions() & ~kRaisedFrame);
 
 1697          fClient->NeedRedraw(fPimpl->fPlane, kTRUE);
 
 1702       ret = HandleButtonPress(&ev);
 
 1707    if ((fDragging || fMoveWaiting) && (!ev.fState || (ev.fState == kKeyShiftMask)) &&
 
 1708        fPimpl->fButtonPressed) {
 
 1710       ev.fType = kButtonRelease;
 
 1713       ret = HandleButtonRelease(&ev);
 
 1718    fPimpl->fButtonPressed = (ev.fState & kButton1Mask) ||
 
 1719                             (ev.fState & kButton2Mask) ||
 
 1720                             (ev.fState & kButton3Mask);
 
 1722    if ((ev.fYRoot == gy) && (ev.fXRoot == gx)) 
return kFALSE;
 
 1727    if (!fMoveWaiting && !fDragging && !ev.fState) {
 
 1728       if (!CheckDragResize(&ev) && fClient->GetWindowById(ev.fWindow)) {
 
 1729          HighlightCompositeFrame(ev.fWindow);
 
 1731    } 
else if (ev.fState & kButton1Mask) {
 
 1741 Bool_t TGuiBldDragManager::RecognizeGesture(Event_t *event, TGFrame *frame)
 
 1747    if (((event->fCode != kButton1) && (event->fCode != kButton3)) ||
 
 1748        !frame || !fClient->IsEditable()) {
 
 1752    TGFrame *context_fr = 0;
 
 1753    Bool_t mdi = kFALSE;
 
 1756    if (frame->IsEditable() && frame->InheritsFrom(TGMdiFrame::Class())) {
 
 1762    if (event->fCode == kButton3) {
 
 1763       if (!fPimpl->fSpacePressedFrame) {
 
 1766             context_fr = fSelected;
 
 1769          context_fr = fPimpl->fSpacePressedFrame;
 
 1772       HandleButon3Pressed(event, context_fr);
 
 1776    fDragType = kDragNone;
 
 1778    if (!fSelectionIsOn) {
 
 1779       fPimpl->fX0 = 
event->fXRoot;
 
 1780       fPimpl->fY0 = 
event->fYRoot;
 
 1784    fPimpl->fClickFrame = frame;
 
 1786    if (fBuilder && fBuilder->IsExecutable() &&
 
 1787        frame->InheritsFrom(TGCompositeFrame::Class())) {
 
 1789       frame->SetEditable(kTRUE);
 
 1791       fDragType = kDragLasso;
 
 1795    if (event->fState & kKeyShiftMask) {
 
 1798       if (frame == fPimpl->fGrab) {
 
 1800          fDragType = kDragCopy;
 
 1801          gVirtualX->SetCursor(frame->GetId(), gVirtualX->CreateCursor(kMove));
 
 1806       if (!fSelectionIsOn) {
 
 1807          fSelectionIsOn = kTRUE;
 
 1809          fPimpl->fX = 
event->fXRoot;
 
 1810          fPimpl->fY = 
event->fYRoot;
 
 1811          fDragType = kDragLasso;
 
 1817    CheckDragResize(event);
 
 1819    if (frame->IsEditable()) {
 
 1822       if (fDragType != kDragResize) {
 
 1825          if (frame == fPimpl->fGrab) {
 
 1827             fDragType = kDragMove;
 
 1828             gVirtualX->SetCursor(frame->GetId(), gVirtualX->CreateCursor(kMove));
 
 1832          fDragType = kDragLasso;
 
 1834    } 
else if ((fDragType != kDragResize) && !fPimpl->fSpacePressedFrame) {
 
 1837       if (!fPimpl->fGrab && frame->InheritsFrom(TGCanvas::Class()))  {
 
 1838          TGFrame *cont = ((TGCanvas*)frame)->GetContainer();
 
 1840          if (!cont->IsEditable()) {
 
 1841             cont->SetEditable(kTRUE);
 
 1842             fDragType = kDragLasso;
 
 1848       SelectFrame(frame, event->fState & kKeyShiftMask);
 
 1851    if ((fDragType == kDragNone) && !fPimpl->fSpacePressedFrame) {
 
 1852       SwitchEditable(frame);
 
 1856       CheckDragResize(event);
 
 1858       if (fDragType == kDragNone) {
 
 1866    gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(),
 
 1868                                    event->fXRoot, 
event->fYRoot,
 
 1869                                    fPimpl->fXf, fPimpl->fYf, c);
 
 1870    fPimpl->fX = 
event->fXRoot;
 
 1871    fPimpl->fY = 
event->fYRoot;
 
 1873    fMoveWaiting = kTRUE;
 
 1882 void TGuiBldDragManager::HandleButon3Pressed(Event_t *event, TGFrame *frame)
 
 1884    if (fStop || !frame) {
 
 1888    if (fClient->GetWaitForEvent() == kUnmapNotify) {
 
 1892    if (frame == fSelected) {
 
 1893       Menu4Frame(frame, event->fXRoot, event->fYRoot);
 
 1894    } 
else if (frame->IsEditable())  {
 
 1896          Menu4Lasso(event->fXRoot, event->fYRoot);
 
 1898          Menu4Frame(frame, event->fXRoot, event->fYRoot);
 
 1901       TGFrame *base = InEditable(frame->GetId());
 
 1904          Menu4Frame(base, event->fXRoot, event->fYRoot);
 
 1906          Menu4Frame(frame, event->fXRoot, event->fYRoot);
 
 1914 Bool_t TGuiBldDragManager::HandleButton(Event_t *event)
 
 1920    if (event->fCode != kButton3) {
 
 1924    if (event->fType == kButtonPress) {
 
 1925       return HandleButtonPress(event);
 
 1927       return HandleButtonRelease(event);
 
 1934 Bool_t TGuiBldDragManager::HandleConfigureNotify(Event_t *event)
 
 1940    TGWindow *w = fClient->GetWindowById(event->fWindow);
 
 1946    fPimpl->fCompacted = kFALSE;
 
 1953 Bool_t TGuiBldDragManager::HandleExpose(Event_t *event)
 
 1959    static Long64_t was = gSystem->Now();
 
 1960    static Window_t win = 0;
 
 1961    Long64_t now = gSystem->Now();
 
 1963    if (event->fCount || (win == event->fWindow) || (now-was < 50) || fDragging) {
 
 1965          HideGrabRectangles();
 
 1971       HideGrabRectangles();
 
 1972       gMenuDialog->RaiseWindow();
 
 1979       if (IsSelectedVisible()) {
 
 1980          DrawGrabRectangles();
 
 1984    win = 
event->fWindow;
 
 1993 Bool_t TGuiBldDragManager::HandleEvent(Event_t *event)
 
 1999    if (IgnoreEvent(event)) {
 
 2003    switch (event->fType) {
 
 2006          return HandleExpose(event);
 
 2008       case kConfigureNotify:
 
 2009          while (gVirtualX->CheckEvent(fId, kConfigureNotify, *event))
 
 2011          return HandleConfigureNotify(event);
 
 2015          return HandleKey(event);
 
 2024             Int_t dbl_clk = kFALSE;
 
 2026             static Window_t gDbw = 0;
 
 2027             static Long_t gLastClick = 0;
 
 2028             static UInt_t gLastButton = 0;
 
 2029             static Int_t gDbx = 0;
 
 2030             static Int_t gDby = 0;
 
 2032             if ((event->fTime - gLastClick < 350) &&
 
 2033                 (event->fCode == gLastButton) &&
 
 2034                 (TMath::Abs(event->fXRoot - gDbx) < 6) &&
 
 2035                 (TMath::Abs(event->fYRoot - gDby) < 6) &&
 
 2036                 (event->fWindow == gDbw)) {
 
 2041                if (event->fState & kKeyControlMask) {
 
 2042                   HandleAction(kEndEditAct);
 
 2044                } 
else if (!(event->fState & 0xFF)) {
 
 2045                   TGFrame *w = (TGFrame*)fClient->GetWindowById(event->fWindow);
 
 2047                   if (w && (w->GetEditDisabled() & kEditDisableBtnEnable)) {
 
 2048                      return w->HandleDoubleClick(event);
 
 2050                   if (SaveFrame(fTmpBuildFile.Data())) {
 
 2051                      gROOT->Macro(fTmpBuildFile.Data());
 
 2054                   if (fBuilder) fBuilder->HandleMenu(kGUIBLD_FILE_START);
 
 2058                gDbw = 
event->fWindow;
 
 2059                gLastClick = 
event->fTime;
 
 2060                gLastButton = 
event->fCode;
 
 2061                gDbx = 
event->fXRoot;
 
 2062                gDby = 
event->fYRoot;
 
 2064                Bool_t ret = HandleButtonPress(event);
 
 2071       case kButtonRelease:
 
 2072          return HandleButtonRelease(event);
 
 2080          while (gVirtualX->CheckEvent(fId, kMotionNotify, *event))
 
 2082          return HandleMotion(event);
 
 2084       case kClientMessage:
 
 2085          return HandleClientMessage(event);
 
 2087       case kDestroyNotify:
 
 2088          return HandleDestroyNotify(event);
 
 2090       case kSelectionNotify:
 
 2094       case kSelectionRequest:
 
 2098       case kSelectionClear:
 
 2102       case kColormapNotify:
 
 2117 Bool_t TGuiBldDragManager::HandleDoubleClick(Event_t *)
 
 2129 TGFrame *TGuiBldDragManager::GetBtnEnableParent(TGFrame *fr)
 
 2131    TGWindow *parent = fr;
 
 2133    while (parent && (parent != fClient->GetDefaultRoot())) {
 
 2134       if (parent->GetEditDisabled() & kEditDisableBtnEnable) {
 
 2135          return (TGFrame*)parent;
 
 2137       parent = (TGWindow*)parent->GetParent();
 
 2145 void TGuiBldDragManager::UnmapAllPopups()
 
 2147    TList *li = fClient->GetListOfPopups();
 
 2148    if (!li->GetEntries()) {
 
 2155    while ((pup = (TGPopupMenu*)next())) {
 
 2157       fClient->ResetWaitFor(pup);
 
 2159    gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
 
 2165 Bool_t TGuiBldDragManager::HandleButtonPress(Event_t *event)
 
 2171    fPimpl->fButtonPressed = kTRUE;
 
 2172    fPimpl->fPlacePopup = kFALSE;
 
 2174    if (fPimpl->fPlane) {
 
 2175       fPimpl->fPlane->ChangeOptions(fPimpl->fPlane->GetOptions() & ~kRaisedFrame);
 
 2176       fClient->NeedRedraw(fPimpl->fPlane, kTRUE);
 
 2180       gMenuDialog->RaiseWindow();
 
 2185    if (gVirtualX->InheritsFrom(
"TGX11") && fBuilder &&
 
 2186        fBuilder->GetToolDock()->IsUndocked()) {
 
 2187       fBuilder->GetToolDock()->GetUndocked()->RaiseWindow();
 
 2191    if (fgGlobalColorDialog && fgGlobalColorDialog->IsMapped()) {
 
 2192       fgGlobalColorDialog->RaiseWindow();
 
 2196    if ( ((event->fCode != kButton1) && (event->fCode != kButton3)) ||
 
 2197         (event->fType != kButtonPress) || IgnoreEvent(event)) {
 
 2204    Window_t w = GetWindowFromPoint(event->fXRoot, event->fYRoot);
 
 2208       fr = (TGFrame*)fClient->GetWindowById(w);
 
 2214       if (!IsEventsDisabled(fr)) {
 
 2215          TGFrame *btnframe = GetBtnEnableParent(fr);
 
 2217             event->fUser[0] = fr->GetId();
 
 2218             btnframe->HandleButton(event);
 
 2222       if (IsGrabDisabled(fr)) {
 
 2223          fr = GetEditableParent(fr);
 
 2233    return RecognizeGesture(event, fr);
 
 2239 Bool_t TGuiBldDragManager::HandleButtonRelease(Event_t *event)
 
 2246    if (fClient->GetWaitForEvent() == kUnmapNotify) {
 
 2250    TGWindow *w = fClient->GetWindowById(event->fWindow);
 
 2252    if (w && !IsEventsDisabled(w)) {
 
 2253       TGFrame *btnframe = GetBtnEnableParent((TGFrame*)w);
 
 2255          event->fUser[0] = w->GetId();
 
 2256          btnframe->HandleButton(event);
 
 2260    fPimpl->fButtonPressed = kFALSE;
 
 2261    gVirtualX->SetCursor(fClient->GetRoot()->GetId(), gVirtualX->CreateCursor(kPointer));
 
 2263    fSelectionIsOn &= (
event->fState & kKeyShiftMask);
 
 2270    if (fPimpl->fClickFrame && !fSelectionIsOn) {
 
 2273       if ((fPimpl->fClickFrame == fPimpl->fGrab) && (fSelected == fPimpl->fGrab) &&
 
 2274            !fPimpl->fGrab->IsEditable()) {
 
 2275          SwitchEditable(fPimpl->fClickFrame);
 
 2279       } 
else if (!fPimpl->fGrab || ((fPimpl->fClickFrame != fPimpl->fGrab) &&
 
 2280                                     (fPimpl->fClickFrame != fSelected))) {
 
 2281          SelectFrame(fPimpl->fClickFrame);
 
 2287    SelectFrame(fPimpl->fGrab);
 
 2295 Bool_t TGuiBldDragManager::HandleKey(Event_t *event)
 
 2303    Bool_t ret = kFALSE;
 
 2305    static TString dir(
".");
 
 2306    static Bool_t overwr = kFALSE;
 
 2309    TGWindow *w = fClient->GetWindowById(GetWindowFromPoint(event->fXRoot, event->fYRoot));
 
 2311    if (!w || !fPimpl) {
 
 2315    if (w->GetEditDisabled() & kEditDisableKeyEnable) {
 
 2316       return ((TGFrame*)w)->HandleKey(event);
 
 2319    if (event->fType != kGKeyPress) {
 
 2323    if (IsEditDisabled(w)) {
 
 2324       TGFrame *parent = GetEditableParent((TGFrame*)w);
 
 2326          event->fWindow = parent->GetId();
 
 2327          parent->HandleKey(event);
 
 2329          return ((TGFrame*)w)->HandleKey(event);
 
 2333    fPimpl->fSpacePressedFrame = 0;
 
 2335    if (fPimpl->fPlane) {
 
 2336       fPimpl->fPlane->ChangeOptions(fPimpl->fPlane->GetOptions() & ~kRaisedFrame);
 
 2337       fClient->NeedRedraw(fPimpl->fPlane, kTRUE);
 
 2342    fi.fFileTypes = gSaveMacroTypes;
 
 2343    fi.fIniDir    = StrDup(dir);
 
 2344    fi.fOverwrite = overwr;
 
 2346    gVirtualX->LookupString(event, tmp, 
sizeof(tmp), keysym);
 
 2348    if (event->fState & kKeyControlMask) {
 
 2350       switch ((EKeySym)keysym & ~0x20) {
 
 2353             HandleReturn(kTRUE);
 
 2365             if (fPimpl->fClickFrame && !fPimpl->fClickFrame->IsEditable()) {
 
 2366                fPimpl->fClickFrame->SetEditable(kTRUE);
 
 2373             if (fPimpl->fGrab ) {
 
 2381             if (fPimpl->fGrab && (fPimpl->fClickFrame != fClient->GetRoot())) {
 
 2407                fBuilder->NewProject();
 
 2409                TGMainFrame *main = 
new TGMainFrame(fClient->GetDefaultRoot(), 300, 300);
 
 2411                main->SetEditable(kTRUE);
 
 2417                fBuilder->NewProject();
 
 2419                TGMainFrame *main = 
new TGMainFrame(fClient->GetDefaultRoot(), 300, 300);
 
 2421                main->SetEditable(kTRUE);
 
 2423             new TGFileDialog(fClient->GetDefaultRoot(), 
this, kFDSave, &fi);
 
 2425             if (!fi.fFilename) 
return kTRUE;
 
 2427             overwr = fi.fOverwrite;
 
 2428             fname = gSystem->BaseName(gSystem->UnixPathName(fi.fFilename));
 
 2430             if (fname.EndsWith(
".C")) {
 
 2431                gROOT->Macro(fname.Data());
 
 2434                new TGMsgBox(fClient->GetDefaultRoot(), 
this, 
"Error...",
 
 2435                             TString::Format(
"file (%s) must have extension .C", fname.Data()),
 
 2436                             kMBIconExclamation, kMBRetry | kMBCancel, &retval);
 
 2437                if (retval == kMBRetry) {
 
 2447       switch ((EKeySym)keysym) {
 
 2449          case kKey_Backspace:
 
 2450             HandleDelete(event->fState & kKeyShiftMask);
 
 2456             HandleReturn(kFALSE);
 
 2464                HandleAlignment(keysym, event->fState & kKeyShiftMask);
 
 2465             } 
else if (fPimpl->fGrab) {
 
 2466                HandleLayoutOrder((keysym == kKey_Right) || (keysym == kKey_Down));
 
 2472             if (fPimpl->fGrab) {
 
 2473                SwitchEditable(fPimpl->fGrab);
 
 2475                TGFrame *p = (TGFrame*)GetEditableParent(fPimpl->fGrab);
 
 2478                   if (p == fBuilder->GetMdiMain()->GetCurrent()) {
 
 2482                      fSource = fPimpl->fSpacePressedFrame = p;
 
 2493       fBuilder->SetAction(0);
 
 2507 void TGuiBldDragManager::ReparentFrames(TGFrame *newfr, TGCompositeFrame *oldfr)
 
 2509    if (fStop || !fClient->IsEditable() || (newfr == fClient->GetDefaultRoot())) {
 
 2513    Int_t x0, y0, xx, yy;
 
 2515    static TGLayoutHints *hints = 
new TGLayoutHints(kLHintsNormal, 2, 2, 2, 2);
 
 2517    if (!newfr || !newfr->GetId() || !oldfr || !oldfr->GetId()) 
return;
 
 2519    gVirtualX->TranslateCoordinates(newfr->GetId(), oldfr->GetId(),
 
 2522    x0 = x0 < 0 ? 0 : x0;
 
 2523    y0 = y0 < 0 ? 0 : y0;
 
 2524    Int_t x = x0 + newfr->GetWidth();
 
 2525    Int_t y = y0 + newfr->GetHeight();
 
 2527    TGCompositeFrame *comp = 0;
 
 2529    if (newfr->InheritsFrom(TGCompositeFrame::Class())) {
 
 2530       comp = (TGCompositeFrame*)newfr;
 
 2531       comp->SetLayoutBroken();
 
 2534    TIter next(oldfr->GetList());
 
 2537    while ((el = (TGFrameElement*)next())) {
 
 2538       TGFrame *frame = el->fFrame;
 
 2540       if ((frame->GetX() >= x0) && (frame->GetY() >= y0) &&
 
 2541           (frame->GetX() + (Int_t)frame->GetWidth() <= x) &&
 
 2542           (frame->GetY() + (Int_t)frame->GetHeight() <= y)) {
 
 2544          if (frame == fPimpl->fGrab) {
 
 2548          oldfr->RemoveFrame(frame);
 
 2550          gVirtualX->TranslateCoordinates(oldfr->GetId(), newfr->GetId(),
 
 2551                                         frame->GetX(), frame->GetY(), xx, yy, c);
 
 2553          frame->ReparentWindow(newfr, xx, yy);
 
 2556             comp->AddFrame(frame, hints); 
 
 2565 TList *TGuiBldDragManager::GetFramesInside(Int_t x0, Int_t y0, Int_t x, Int_t y)
 
 2573    if (!fClient->GetRoot()->InheritsFrom(TGCompositeFrame::Class())) {
 
 2577    TList *list = 
new TList();
 
 2580    x0 = TMath::Min(xx, x); x = TMath::Max(xx, x);
 
 2581    y0 = TMath::Min(yy, y); y = TMath::Max(yy, y);
 
 2583    TIter next(((TGCompositeFrame*)fClient->GetRoot())->GetList());
 
 2586    while ((el = (TGFrameElement*)next())) {
 
 2587       if ((el->fFrame->GetX() >= x0) && (el->fFrame->GetY() >= y0) &&
 
 2588           (el->fFrame->GetX() + (Int_t)el->fFrame->GetWidth() <= x) &&
 
 2589           (el->fFrame->GetY() + (Int_t)el->fFrame->GetHeight() <= y)) {
 
 2590          list->Add(el->fFrame);
 
 2593    if (list->IsEmpty()) {
 
 2603 void TGuiBldDragManager::DropCanvas(TGCanvas *canvas)
 
 2609    TGCompositeFrame *comp = (TGCompositeFrame*)canvas->GetParent();
 
 2610    comp->SetEditable(kTRUE);
 
 2612    TGCompositeFrame *cont = (TGCompositeFrame*)canvas->GetContainer();
 
 2613    Int_t x = canvas->GetX();
 
 2614    Int_t y = canvas->GetY();
 
 2616    cont->SetEditDisabled(cont->GetEditDisabled() & ~kEditDisableGrab);
 
 2617    cont->ReparentWindow(comp, x, y);
 
 2618    canvas->SetContainer(0);
 
 2619    comp->AddFrame(cont);
 
 2620    DeleteFrame(canvas);
 
 2623       TString str = cont->ClassName();
 
 2625       str += cont->GetName();
 
 2627       fBuilder->UpdateStatusBar(str.Data());
 
 2635 void TGuiBldDragManager::PutToCanvas(TGCompositeFrame *cont)
 
 2637    if (fStop || !cont) {
 
 2641    TGCompositeFrame *comp = (TGCompositeFrame*)cont->GetParent();
 
 2642    comp->SetEditable(kTRUE);
 
 2644    UInt_t w = cont->GetWidth()/2;
 
 2645    UInt_t h = cont->GetHeight()/2;
 
 2647    w = w < 100 ? 100 : w;
 
 2648    h = h < 100 ? 100 : h;
 
 2650    TGCanvas *canvas = 
new TGCanvas(comp, w, h);
 
 2651    canvas->Move(cont->GetX(), cont->GetY());
 
 2652    comp->RemoveFrame(cont);
 
 2653    comp->AddFrame(canvas);
 
 2654    cont->ReparentWindow(canvas->GetViewPort());
 
 2655    canvas->SetContainer(cont);
 
 2656    cont->SetCleanup(kDeepCleanup);
 
 2657    canvas->MapSubwindows();
 
 2658    canvas->MapWindow();
 
 2659    SelectFrame(canvas);
 
 2662       fBuilder->UpdateStatusBar(
"Grab action performed. Presss Cntrl-Return to Drop grabbed frame.");
 
 2687 void TGuiBldDragManager::HandleReturn(Bool_t on)
 
 2693    Int_t x0, y0, x, y, xx, yy;
 
 2695    TGCompositeFrame *parent = 0;
 
 2698    if (!fClient->GetRoot()->InheritsFrom(TGCompositeFrame::Class()) ||
 
 2699        !fClient->IsEditable()) {
 
 2704    if (fPimpl->fGrab && fPimpl->fGrab->IsEditable()) {
 
 2705       ((TGFrame*)fPimpl->fGrab->GetParent())->SetEditable(kTRUE);
 
 2708    if (fPimpl->fGrab && !fLassoDrawn) {
 
 2710          if (fPimpl->fGrab->InheritsFrom(TGCompositeFrame::Class()) &&
 
 2711             !fPimpl->fGrab->InheritsFrom(TGCanvas::Class()) &&
 
 2712             !fPimpl->fGrab->InheritsFrom(TGContainer::Class()) &&
 
 2713             CanChangeLayout(fPimpl->fGrab) &&
 
 2714             CanChangeLayout((TGWindow*)fPimpl->fGrab->GetParent())) {
 
 2715             PutToCanvas((TGCompositeFrame*)fPimpl->fGrab);
 
 2720          if ((fPimpl->fGrab->IsA() == TGCanvas::Class()) &&
 
 2721              !((TGCanvas*)fPimpl->fGrab)->GetContainer()->InheritsFrom(TGContainer::Class()) &&
 
 2722              CanChangeLayout((TGWindow*)fPimpl->fGrab->GetParent())) {
 
 2723             DropCanvas((TGCanvas*)fPimpl->fGrab);
 
 2729    TGCompositeFrame *comp = (TGCompositeFrame*)fClient->GetRoot();
 
 2733       gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(),
 
 2734                                       fClient->GetRoot()->GetId(),
 
 2735                                       fPimpl->fX, fPimpl->fY, x, y, c);
 
 2736       gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(),
 
 2737                                       fClient->GetRoot()->GetId(),
 
 2738                                       fPimpl->fX0, fPimpl->fY0, x0, y0, c);
 
 2741       x0 = TMath::Min(xx, x); x = TMath::Max(xx, x);
 
 2742       y0 = TMath::Min(yy, y); y = TMath::Max(yy, y);
 
 2744       li = GetFramesInside(x0, y0, x, y);
 
 2747          parent = 
new TGCompositeFrame(comp, x - x0, y - y0);
 
 2748          parent->MoveResize(x0, y0, x - x0, y - y0);
 
 2749          ReparentFrames(parent, comp);
 
 2751          comp->AddFrame(parent);
 
 2752          parent->MapWindow();
 
 2753          SetLassoDrawn(kFALSE);
 
 2754          SelectFrame(parent);
 
 2757             TString str = 
"Grab action performed.";
 
 2758             str += 
" Press Cntrl-Return to Drop grabbed frames.";
 
 2759             str += 
" Presss Return for TCanvas Grab";
 
 2760             fBuilder->UpdateStatusBar(str.Data());
 
 2763    } 
else if (on && fPimpl->fGrab) {
 
 2766       if (!CanChangeLayout(fPimpl->fGrab) ||
 
 2767           !CanChangeLayout((TGWindow*)fPimpl->fGrab->GetParent())) {
 
 2769             fBuilder->UpdateStatusBar(
"Drop action disabled");
 
 2774       if (fPimpl->fGrab->InheritsFrom(TGCompositeFrame::Class())) {
 
 2775          parent = (TGCompositeFrame*)fPimpl->fGrab;
 
 2780          ReparentFrames(comp, parent);
 
 2781          DeleteFrame(fPimpl->fGrab);
 
 2786             fBuilder->UpdateStatusBar(
"Drop action performed");
 
 2796 void TGuiBldDragManager::HandleAlignment(Int_t to, Bool_t lineup)
 
 2802    Int_t x0, y0, x, y, xx, yy;
 
 2804    TGCompositeFrame *comp = 0;
 
 2806    if (!fClient->GetRoot()->InheritsFrom(TGCompositeFrame::Class()) ||
 
 2807        !fClient->IsEditable()) {
 
 2812       gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(),
 
 2813                                       fClient->GetRoot()->GetId(),
 
 2814                                       fPimpl->fX, fPimpl->fY, x, y, c);
 
 2815       gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(),
 
 2816                                       fClient->GetRoot()->GetId(),
 
 2817                                       fPimpl->fX0, fPimpl->fY0, x0, y0, c);
 
 2820       x0 = TMath::Min(xx, x); x = TMath::Max(xx, x);
 
 2821       y0 = TMath::Min(yy, y); y = TMath::Max(yy, y);
 
 2823       comp = (TGCompositeFrame*)fClient->GetRoot();
 
 2828       TIter next(comp->GetList());
 
 2832       while ((el = (TGFrameElement*)next())) {
 
 2833          TGFrame *fr = el->fFrame;
 
 2835          if ((fr->GetX() >= x0) && (fr->GetY() >= y0) &&
 
 2836              (fr->GetX() + (Int_t)fr->GetWidth() <= x) &&
 
 2837              (fr->GetY() + (Int_t)fr->GetHeight() <= y)) {
 
 2839             switch ((EKeySym)to) {
 
 2841                   fr->Move(x0, fr->GetY());
 
 2844                      if (prev) fr->Move(fr->GetX(), prev->GetY() + prev->GetHeight());
 
 2845                      else fr->Move(x0, y0);
 
 2849                   fr->Move(x - fr->GetWidth(), fr->GetY());
 
 2851                      if (prev) fr->Move(fr->GetX(), prev->GetY() + prev->GetHeight());
 
 2852                      else fr->Move(x - fr->GetWidth(), y0);
 
 2856                   fr->Move(fr->GetX(), y0);
 
 2858                      if (prev) fr->Move(prev->GetX() + prev->GetWidth(), fr->GetY());
 
 2859                      else fr->Move(x0, y0);
 
 2863                   fr->Move(fr->GetX(), y - fr->GetHeight());
 
 2865                      if (prev) fr->Move(prev->GetX() + prev->GetWidth(), fr->GetY());
 
 2866                      else fr->Move(x0, y - fr->GetHeight());
 
 2892 void TGuiBldDragManager::HandleDelete(Bool_t crop)
 
 2898    Int_t x0, y0, x, y, xx, yy, w, h;
 
 2901    if (!fClient->GetRoot()->InheritsFrom(TGCompositeFrame::Class()) ||
 
 2902        !fClient->IsEditable()) {
 
 2906    TGCompositeFrame *comp = 0;
 
 2907    Bool_t fromGrab = kFALSE;
 
 2908    TGFrame *frame = fPimpl->fGrab;
 
 2910    if (fBuilder && crop) {
 
 2911       comp = fBuilder->FindEditableMdiFrame(fClient->GetRoot());
 
 2913       comp = (TGCompositeFrame*)fClient->GetRoot();
 
 2916    if (frame && !CanChangeLayout((TGWindow*)frame->GetParent())) {
 
 2917       frame = GetMovableParent(frame);
 
 2920          TString str = fPimpl->fGrab->ClassName();
 
 2922          str += fPimpl->fGrab->GetName();
 
 2923          str += 
" cannot be deleted";
 
 2926             fBuilder->UpdateStatusBar(str.Data());
 
 2933    if (frame && !fLassoDrawn && crop) {
 
 2934       gVirtualX->TranslateCoordinates(frame->GetId(),
 
 2935                                       fClient->GetDefaultRoot()->GetId(),
 
 2937                                       fPimpl->fX0, fPimpl->fY0, c);
 
 2939       fPimpl->fX = fPimpl->fX0 + frame->GetWidth()+4;
 
 2940       fPimpl->fY = fPimpl->fY0 + frame->GetHeight()+4;
 
 2944    x0 = fPimpl->fX0; y0 = fPimpl->fY0;
 
 2945    x  = fPimpl->fX;  y  = fPimpl->fY;
 
 2947       gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(),
 
 2949                                       fPimpl->fX, fPimpl->fY, x, y, c);
 
 2950       gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(),
 
 2952                                       fPimpl->fX0, fPimpl->fY0, x0, y0, c);
 
 2956    x0 = TMath::Min(xx, x); x = TMath::Max(xx, x);
 
 2957    y0 = TMath::Min(yy, y); y = TMath::Max(yy, y);
 
 2961    if (fLassoDrawn || fromGrab) {
 
 2963          TIter next(comp->GetList());
 
 2966          while ((el = (TGFrameElement*)next())) {
 
 2967             TGFrame *fr = el->fFrame;
 
 2969             if ((fr->GetX() >= x0) && (fr->GetY() >= y0) &&
 
 2970                 (fr->GetX() + (Int_t)fr->GetWidth() <= x) &&
 
 2971                 (fr->GetY() + (Int_t)fr->GetHeight() <= y)) {
 
 2975                   fr->Move(fr->GetX() - x0, fr->GetY() - y0);
 
 2984             gVirtualX->TranslateCoordinates(comp->GetId(), comp->GetParent()->GetId(),
 
 2987             comp->MoveResize(xx, yy, w, h);
 
 2989             if (comp->GetParent()->InheritsFrom(TGMdiDecorFrame::Class())) {
 
 2990                TGMdiDecorFrame *decor = (TGMdiDecorFrame *)comp->GetParent();
 
 2992                gVirtualX->TranslateCoordinates(decor->GetId(), decor->GetParent()->GetId(),
 
 2995                Int_t b = 2 * decor->GetBorderWidth();
 
 2996                decor->MoveResize(xx, yy, comp->GetWidth() + b,
 
 2997                                  comp->GetHeight() + b + decor->GetTitleBar()->GetDefaultHeight());
 
 3007    SetLassoDrawn(kFALSE);
 
 3011       fBuilder->UpdateStatusBar(crop ? 
"Crop action performed" : 
"Delete action performed");
 
 3018 void TGuiBldDragManager::DeleteFrame(TGFrame *frame)
 
 3020    if (fStop || !frame) {
 
 3025    fEditor->RemoveFrame(frame);
 
 3027    frame->UnmapWindow();
 
 3029    TGCompositeFrame *comp = 0;
 
 3031    if (frame->GetParent()->InheritsFrom(TGCompositeFrame::Class())) {
 
 3032       comp = (TGCompositeFrame*)frame->GetParent();
 
 3036       comp->RemoveFrame(frame);
 
 3039    if (frame == fPimpl->fGrab) {
 
 3043    fClient->UnregisterWindow(frame);
 
 3046    frame->ReparentWindow(fClient->GetDefaultRoot());
 
 3052 void TGuiBldDragManager::HandleCut()
 
 3054    if (fStop || !fPimpl->fGrab) {
 
 3059    fPimpl->fGrab = GetMovableParent(fPimpl->fGrab);
 
 3061    DeleteFrame(fPimpl->fGrab);
 
 3069 void TGuiBldDragManager::HandleCopy(Bool_t brk_layout)
 
 3071    if (fStop || !fPimpl->fGrab) {
 
 3075    TGMainFrame *tmp = 
new TGMainFrame(fClient->GetDefaultRoot(),
 
 3076                                       fPimpl->fGrab->GetWidth(),
 
 3077                                       fPimpl->fGrab->GetHeight());
 
 3080    Int_t x0 = fPimpl->fGrab->GetX();
 
 3081    Int_t y0 = fPimpl->fGrab->GetY();
 
 3084    TString name = fPimpl->fGrab->GetParent()->GetName();
 
 3086    ((TGWindow*)fPimpl->fGrab->GetParent())->SetName(tmp->GetName());
 
 3088    fPimpl->fGrab->SetX(0);
 
 3089    fPimpl->fGrab->SetY(0);
 
 3091    TGFrameElement *fe = fPimpl->fGrab->GetFrameElement();
 
 3094       tmp->GetList()->Add(fe);
 
 3097    tmp->SetLayoutBroken(brk_layout);
 
 3100       tmp->SetMWMHints(kMWMDecorAll, kMWMFuncAll, kMWMInputFullApplicationModal);
 
 3101       tmp->SetWMSize(tmp->GetWidth(), tmp->GetHeight());
 
 3102       tmp->SetWMSizeHints(tmp->GetDefaultWidth(), tmp->GetDefaultHeight(), 10000, 10000, 0, 0);
 
 3103       const char *short_name = gSystem->BaseName(fPasteFileName.Data());
 
 3104       tmp->SetWindowName(short_name);
 
 3105       tmp->SetIconName(short_name);
 
 3106       tmp->SetClassHints(short_name, short_name);
 
 3108       if (gVirtualX->InheritsFrom(
"TGX11")) tmp->SetIconPixmap(
"bld_rgb.xpm");
 
 3110    Bool_t quite =  brk_layout || (fPasteFileName == fTmpBuildFile);
 
 3111    tmp->SaveSource(fPasteFileName.Data(), quite ? 
"keep_names quiet" : 
"keep_names");
 
 3112    tmp->GetList()->Remove(fe);
 
 3114    fPimpl->fGrab->SetX(x0);
 
 3115    fPimpl->fGrab->SetY(y0);
 
 3117    ((TGWindow*)fPimpl->fGrab->GetParent())->SetName(name.Data());
 
 3120       TString str = fPimpl->fGrab->ClassName();
 
 3122       str += fPimpl->fGrab->GetName();
 
 3123       str += 
" copied to clipboard";
 
 3124       fBuilder->UpdateStatusBar(str.Data());
 
 3133 void TGuiBldDragManager::HandlePaste()
 
 3142    if (gSystem->AccessPathName(fPasteFileName.Data())) {
 
 3147    gROOT->Macro(fPasteFileName.Data());
 
 3150    TGFrame *root = (TGFrame*)fClient->GetRoot();
 
 3152    if (!fPimpl->fReplaceOn) {
 
 3153       gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(),
 
 3155                                       fPimpl->fX0, fPimpl->fY0, xp, yp, c);
 
 3163          TGMainFrame *main = (TGMainFrame*)fPasteFrame;
 
 3164          TGFrame *paste = ((TGFrameElement*)main->GetList()->First())->fFrame;
 
 3166          UInt_t w = paste->GetWidth();
 
 3167          UInt_t h = paste->GetHeight();
 
 3169          if (xp + w > root->GetWidth()) {
 
 3170             w = root->GetWidth() - xp -1;
 
 3172          if (yp + h > root->GetHeight()) {
 
 3173             h = root->GetHeight() - yp -1;
 
 3176          paste->Resize(w, h);
 
 3177          fPasteFrame->Move(xp, yp);
 
 3178          fPimpl->fGrab = fPasteFrame;
 
 3186       fBuilder->UpdateStatusBar(
"Paste action performed");
 
 3193 void TGuiBldDragManager::DoReplace(TGFrame *frame)
 
 3195    if (fStop || !frame || !fPimpl->fGrab || !fPimpl->fReplaceOn) {
 
 3199    Int_t w = fPimpl->fGrab->GetWidth();
 
 3200    Int_t h = fPimpl->fGrab->GetHeight();
 
 3201    Int_t x = fPimpl->fGrab->GetX();
 
 3202    Int_t y = fPimpl->fGrab->GetY();
 
 3205       TString str = fPimpl->fGrab->ClassName();
 
 3207       str += fPimpl->fGrab->GetName();
 
 3208       str += 
" replaced by ";
 
 3209       str += frame->ClassName();
 
 3211       str += frame->GetName();
 
 3212       fBuilder->UpdateStatusBar(str.Data());
 
 3215    TGFrameElement *fe = fPimpl->fGrab->GetFrameElement();
 
 3219       fPimpl->fGrab->DestroyWindow();
 
 3220       delete fPimpl->fGrab;
 
 3224       frame->MoveResize(x, y, w, h);
 
 3226       frame->SetFrameElement(fe);
 
 3230    fPimpl->fReplaceOn = kFALSE;
 
 3232    TGWindow *root = (TGWindow *)fClient->GetRoot();
 
 3233    root->SetEditable(kFALSE);
 
 3235    root->SetEditable(kTRUE);
 
 3241 void TGuiBldDragManager::HandleReplace()
 
 3243    if (fStop || !fPimpl->fGrab) {
 
 3247    fPimpl->fReplaceOn = kTRUE;
 
 3250    if (fBuilder && fBuilder->IsExecutable())  {
 
 3251       frame = (TGFrame *)fBuilder->ExecuteAction();
 
 3254       frame = fPasteFrame;
 
 3257    fPimpl->fReplaceOn = kFALSE;
 
 3263 void TGuiBldDragManager::CloneEditable()
 
 3269    TString tmpfile = gSystem->TempDirectory();
 
 3270    char *s = gSystem->ConcatFileName(tmpfile.Data(), TString::Format(
"tmp%d.C",
 
 3271                                      gRandom->Integer(100)));
 
 3277    if (fClient->GetRoot()->InheritsFrom(TGFrame::Class())) {
 
 3278       TGFrame *f = (TGFrame *)fClient->GetRoot();
 
 3279       f->Resize(f->GetWidth() + 10, f->GetHeight() + 10);
 
 3286 Bool_t TGuiBldDragManager::Save(
const char *file)
 
 3288    if (fStop || !fClient->GetRoot() || !fClient->IsEditable()) {
 
 3292    TGMainFrame *main = (TGMainFrame*)fClient->GetRoot()->GetMainFrame();
 
 3293    TGWindow *root = (TGWindow*)fClient->GetRoot();
 
 3294    TString fname = file;
 
 3296    root->SetEditable(kFALSE);
 
 3298    static TImage *img = 0;
 
 3301       img = TImage::Create();
 
 3303    img->FromWindow(main->GetId());
 
 3305    if (!file || !file[0]) {
 
 3306       static TString dir(
".");
 
 3307       static Bool_t overwr = kFALSE;
 
 3310       fi.fFileTypes = gSaveMacroTypes;
 
 3311       fi.fIniDir    = StrDup(dir);
 
 3312       fi.fOverwrite = overwr;
 
 3313       new TGFileDialog(fClient->GetDefaultRoot(), 
this, kFDSave, &fi);
 
 3315       if (!fi.fFilename) 
goto out;
 
 3317       overwr = fi.fOverwrite;
 
 3318       fname = gSystem->BaseName(gSystem->UnixPathName(fi.fFilename));
 
 3321    if (fname.EndsWith(
".C")) {
 
 3322       main->SetMWMHints(kMWMDecorAll, kMWMFuncAll, kMWMInputFullApplicationModal);
 
 3323       main->SetWMSize(main->GetWidth(), main->GetHeight());
 
 3324       main->SetWMSizeHints(main->GetDefaultWidth(), main->GetDefaultHeight(), 10000, 10000, 0, 0);
 
 3325       main->SetWindowName(fname.Data());
 
 3326       main->SetIconName(fname.Data());
 
 3327       main->SetClassHints(fname.Data(), fname.Data());
 
 3329       if (gVirtualX->InheritsFrom(
"TGX11")) main->SetIconPixmap(
"bld_rgb.xpm");
 
 3330       main->SaveSource(fname.Data(), file ? 
"keep_names quiet" : 
"keep_names");
 
 3332       fBuilder->AddMacro(fname.Data(), img);
 
 3336       TString msg = TString::Format(
"file (%s) must have extension .C", fname.Data());
 
 3338       new TGMsgBox(fClient->GetDefaultRoot(), main, 
"Error...", msg.Data(),
 
 3339                    kMBIconExclamation, kMBRetry | kMBCancel, &retval);
 
 3341       if (retval == kMBRetry) {
 
 3347    main->RaiseWindow();
 
 3354 Bool_t TGuiBldDragManager::SaveFrame(
const char *file)
 
 3356    if (fStop || !fClient->GetRoot() || !fClient->IsEditable() ||
 
 3357        !fPimpl->fGrab || !fPimpl->fGrab->InheritsFrom(TGCompositeFrame::Class())) {
 
 3361    TString fname = file;
 
 3363    TGFrame *frame = fPimpl->fGrab;
 
 3364    SetEditable(kFALSE);
 
 3366    static TImage *img = 0;
 
 3369       img = TImage::Create();
 
 3371    img->FromWindow(frame->GetId());
 
 3373    static TString dir(
".");
 
 3374    static Bool_t overwr = kFALSE;
 
 3376    TString sav = fPasteFileName;
 
 3381       fi.fFileTypes = gSaveMacroTypes;
 
 3382       fi.fIniDir    = StrDup(dir);
 
 3383       fi.fOverwrite = overwr;
 
 3384       new TGFileDialog(fClient->GetDefaultRoot(), frame, kFDSave, &fi);
 
 3386       if (!fi.fFilename) {
 
 3391       overwr = fi.fOverwrite;
 
 3392       fname = gSystem->BaseName(gSystem->UnixPathName(fi.fFilename));
 
 3395    if (fname.EndsWith(
".C")) {
 
 3396       fPasteFileName = fname;
 
 3397       fPimpl->fGrab = frame;
 
 3399       TGFrameElement *fe = frame->GetFrameElement();
 
 3402          fe = 
new TGFrameElement();
 
 3404          fe->fState = kIsMapped;
 
 3405          frame->SetFrameElement(fe);
 
 3406          TGCompositeFrame *comp = (TGCompositeFrame*)frame->GetParent();
 
 3407          comp->GetList()->Add(fe);
 
 3410       fe->fLayout = 
new TGLayoutHints(kLHintsExpandX | kLHintsExpandY);
 
 3415       fBuilder->AddMacro(fname.Data(), img);
 
 3418       TString msg = TString::Format(
"file (%s) must have extension .C", fname.Data());
 
 3420       new TGMsgBox(fClient->GetDefaultRoot(), frame, 
"Error...", msg.Data(),
 
 3421                    kMBIconExclamation, kMBRetry | kMBCancel, &retval);
 
 3423       if (retval == kMBRetry) {
 
 3429    fPasteFileName = sav;
 
 3436 static Int_t canResize(TGFrame *frame, Int_t x, Int_t y, UInt_t &w, UInt_t &h)
 
 3438    if (frame->InheritsFrom(TGCompositeFrame::Class())) return 0;
 
 3440    TGCompositeFrame *comp = (TGCompositeFrame*)frame;
 
 3442    TIter next(comp->GetList());
 
 3444    Int_t d = gGuiBldDragManager->GetGridStep();
 
 3447    while ((fe = (TGFrameElement*)next())) {
 
 3448       if (x + fe->fFrame->GetX() + fe->fFrame->GetWidth() > w) {
 
 3449          w = fe->fFrame->GetX() + x  + fe->fFrame->GetWidth();
 
 3452       if (y + fe->fFrame->GetY() + fe->fFrame->GetHeight() > h) {
 
 3453          h = fe->fFrame->GetY() + y + fe->fFrame->GetHeight();
 
 3464 void TGuiBldDragManager::DoResize()
 
 3466    if (fStop || !fClient->IsEditable()) {
 
 3470    TGFrame *fr = fPimpl->fGrab;
 
 3472    if (!fr || IsFixedSize(fr) ||
 
 3473         IsFixedLayout((TGWindow*)fr->GetParent())) {
 
 3475       fr = (TGFrame*)GetResizableParent(fr);
 
 3482    TGCompositeFrame *comp = 0;
 
 3484    if (fr->InheritsFrom(TGCompositeFrame::Class())) {
 
 3485       comp = (TGCompositeFrame*)fr;
 
 3489    Int_t x = fPimpl->fX;
 
 3490    Int_t y = fPimpl->fY;
 
 3493    UInt_t wp = ((TGFrame*)fr->GetParent())->GetWidth() - 2;
 
 3494    UInt_t hp = ((TGFrame*)fr->GetParent())->GetHeight() - 2;
 
 3496    gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(),
 
 3497                                    fr->GetId(), x, y, x, y, c);
 
 3500    HighlightCompositeFrame(fr->GetParent()->GetId());
 
 3502    switch (fPimpl->fResizeType) {
 
 3504          if ((((
int)fr->GetWidth() > x) || (x < 0)) &&
 
 3505              (((
int)fr->GetHeight() > y) || (y < 0))) {
 
 3507             if (fr->GetY() + y < 2) {
 
 3510             if (fr->GetX() + x < 2) {
 
 3513             h = fr->GetHeight() - y;
 
 3514             w = fr->GetWidth() - x;
 
 3518             if (!IsFixedH(fr) && !IsFixedW(fr)) {
 
 3519                fr->MoveResize(x, y, w, h);
 
 3523                fr->MoveResize(x, fr->GetY(), w, fr->GetDefaultHeight());
 
 3527                fr->MoveResize(fr->GetX(), y, fr->GetDefaultWidth(), h);
 
 3533          if ((x > 0) && (((int)fr->GetHeight() > y) || (y < 0))) {
 
 3535             if (fr->GetY() + y < 2) {
 
 3538             h = fr->GetHeight() - y;
 
 3541                w =  fr->GetDefaultWidth();
 
 3543                w = fr->GetX() + x > Int_t(wp) ? wp - fr->GetX() : UInt_t(x);
 
 3548             if (!IsFixedH(fr)) {
 
 3549                fr->MoveResize(x, y, w, h);
 
 3551                fr->Resize(x, fr->GetDefaultHeight());
 
 3556          if (((
int)fr->GetHeight() > y) || (y < 0)) {
 
 3561             if (fr->GetY() + y < 2) {
 
 3564             h = fr->GetHeight() - y;
 
 3569             fr->MoveResize(x, y, w, h);
 
 3573          if ((((
int)fr->GetWidth() > x) || (x < 0)) && (y > 0)) {
 
 3575             if (fr->GetX() + x < 2) {
 
 3578             h = fr->GetY() + y > Int_t(hp) ? hp - fr->GetY() : UInt_t(y);
 
 3579             w = fr->GetWidth() - x;
 
 3582             if (!IsFixedH(fr) && !IsFixedW(fr)) {
 
 3583                fr->MoveResize(x, fr->GetY(), w, h);
 
 3587                fr->MoveResize(x, fr->GetY(), w, fr->GetDefaultHeight());
 
 3591                fr->MoveResize(fr->GetX(), fr->GetY(),
 
 3592                               fr->GetDefaultWidth(), h);
 
 3598          if ((x > 0) && (y > 0)) {
 
 3599             w = !IsFixedW(fr) ? UInt_t(x) : fr->GetDefaultWidth();
 
 3600             h = !IsFixedH(fr) ? UInt_t(y) : fr->GetDefaultHeight();
 
 3602             h = fr->GetY() + h > hp ? hp - fr->GetY() : h;
 
 3603             w = fr->GetX() + w > wp ? wp - fr->GetX() : w;
 
 3616             h = fr->GetY() + y > (Int_t)hp ? hp - fr->GetY() : UInt_t(y);
 
 3623          if ((
int)fr->GetWidth() > x ) {
 
 3628             if (fr->GetX() + x < 2) {
 
 3631             w = fr->GetWidth() - x;
 
 3632             h = fr->GetHeight();
 
 3637             fr->MoveResize(x, y, w, h);
 
 3646             h = fr->GetHeight();
 
 3647             w = fr->GetX() + x > (Int_t)wp ? wp - fr->GetX() : UInt_t(x);
 
 3655    if (comp && (!comp->IsLayoutBroken() || IsFixedLayout(comp))) {
 
 3659    gVirtualX->SetCursor(fClient->GetRoot()->GetId(),
 
 3660                         gVirtualX->CreateCursor(fPimpl->fResizeType));
 
 3662    h = fr->GetHeight();
 
 3665       TString str = fr->ClassName();
 
 3667       str += fr->GetName();
 
 3669       str += TString::Format(
"(%d x %d)", w, h);
 
 3670       fBuilder->UpdateStatusBar(str.Data());
 
 3673    fClient->NeedRedraw(fr, kTRUE);
 
 3675    fEditor->ChangeSelected(fr); 
 
 3681 void TGuiBldDragManager::DoMove()
 
 3683    if (fStop || !fPimpl->fGrab || !fClient->IsEditable()) {
 
 3687    TGWindow *parent = (TGWindow*)fPimpl->fGrab->GetParent();
 
 3690    if (IsFixedLayout(parent) || IsEditDisabled(parent)) {
 
 3694    Int_t x = fPimpl->fX - fPimpl->fXf;
 
 3695    Int_t y = fPimpl->fY - fPimpl->fYf;
 
 3698    static UInt_t w = 0;
 
 3699    static UInt_t h = 0;
 
 3702       gVirtualX->GetWindowSize(gVirtualX->GetDefaultRootWindow(), qq, qq, w, h);
 
 3706    Bool_t move = (x > 0) && (y > 0) && ((x + fPimpl->fGrab->GetWidth()) < (w - 0)) &&
 
 3707                  ((y + fPimpl->fGrab->GetHeight()) < (h - 30));
 
 3711    if (!move && !gVirtualX->InheritsFrom(
"TGX11")) {
 
 3716    fPimpl->fGrab->Move(x, y);
 
 3720       TString str = fPimpl->fGrab->ClassName();
 
 3722       str += fPimpl->fGrab->GetName();
 
 3723       str += 
" is moved to absolute position   ";
 
 3724       str += TString::Format(
"(%d , %d)", x, y);
 
 3725       fBuilder->UpdateStatusBar(str.Data());
 
 3728    CheckTargetUnderGrab();
 
 3734 TGFrame *TGuiBldDragManager::FindMdiFrame(TGFrame *in)
 
 3742    while (p && (p != fClient->GetDefaultRoot()) &&
 
 3743          !p->InheritsFrom(TGMainFrame::Class())) {
 
 3744       if (p->InheritsFrom(TGMdiFrame::Class())) {
 
 3747       p = (TGFrame*)p->GetParent();
 
 3755 void TGuiBldDragManager::RaiseMdiFrame(TGFrame *comp)
 
 3757    if (fStop || !comp) {
 
 3761    if (comp && comp->InheritsFrom(TGMdiFrame::Class()) && fBuilder) {
 
 3762       TGFrame *mdi = fBuilder->FindEditableMdiFrame(comp);
 
 3769       if (fBuilder->GetMdiMain()->GetCurrent() != comp) {
 
 3770          fBuilder->GetMdiMain()->SetCurrent((TGMdiFrame*)comp);
 
 3778 void TGuiBldDragManager::CheckTargetUnderGrab()
 
 3780    if (fStop || !fPimpl->fGrab ) {
 
 3784    Int_t x = fPimpl->fGrab->GetX();
 
 3785    Int_t y = fPimpl->fGrab->GetY();
 
 3786    UInt_t w = fPimpl->fGrab->GetWidth();
 
 3787    UInt_t h = fPimpl->fGrab->GetHeight();
 
 3789    Bool_t ok = CheckTargetAtPoint(x - 1, y - 1);
 
 3792       ok = CheckTargetAtPoint(x + w + 1, y + h + 1);
 
 3796       ok = CheckTargetAtPoint(x + w + 1, y - 1);
 
 3800       ok = CheckTargetAtPoint(x - 1, y + h + 1);
 
 3807 Bool_t TGuiBldDragManager::CheckTargetAtPoint(Int_t x, Int_t y)
 
 3809    if (fStop || !fPimpl->fGrab) {
 
 3813    UInt_t ww = fPimpl->fGrab->GetWidth();
 
 3814    UInt_t hh = fPimpl->fGrab->GetHeight();
 
 3815    Bool_t ret = kFALSE;
 
 3819    Window_t w = GetWindowFromPoint(x, y);
 
 3821    if (w && (w != gVirtualX->GetDefaultRootWindow())) {
 
 3822       win = fClient->GetWindowById(w);
 
 3823       TGCompositeFrame *comp = 0;
 
 3829       if (win->InheritsFrom(TGCompositeFrame::Class())) {
 
 3830          comp = (TGCompositeFrame *)win;
 
 3831       } 
else if (win->GetParent() != fClient->GetDefaultRoot()) {
 
 3832          comp = (TGCompositeFrame *)win->GetParent();
 
 3836          gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(),
 
 3837                                          comp->GetId(), x, y, x, y, c);
 
 3839          RaiseMdiFrame(comp);
 
 3841          if ((comp != fPimpl->fGrab) && (x >= 0) && (y >= 0) &&
 
 3842              (x + ww <= comp->GetWidth()) &&
 
 3843              (y + hh <= comp->GetHeight())) {
 
 3845             if (comp != fTarget) {
 
 3846                comp->HandleDragEnter(fPimpl->fGrab);
 
 3848                if (fTarget) fTarget->HandleDragLeave(fPimpl->fGrab);
 
 3853                   fTarget->HandleDragMotion(fPimpl->fGrab);
 
 3858             fTargetId = comp->GetId();
 
 3864                fTarget->HandleDragLeave(fPimpl->fGrab);
 
 3874       fTarget->HandleDragLeave(fPimpl->fGrab);
 
 3887 Bool_t TGuiBldDragManager::HandleMotion(Event_t *event)
 
 3893    static Long64_t was = gSystem->Now();
 
 3894    static Int_t gy = 
event->fYRoot;
 
 3895    static Int_t gx = 
event->fXRoot;
 
 3897    Long64_t now = gSystem->Now();
 
 3899    if ((now-was < 100) || !(event->fState & kButton1Mask) ||
 
 3900        ((event->fYRoot == gy) && (event->fXRoot == gx))) {
 
 3909       if (fMoveWaiting && ((TMath::Abs(fPimpl->fX - event->fXRoot) > 10) ||
 
 3910           (TMath::Abs(fPimpl->fY - event->fYRoot) > 10))) {
 
 3912          return StartDrag(fSource, event->fXRoot, event->fYRoot);
 
 3915       fPimpl->fX = 
event->fXRoot;
 
 3916       fPimpl->fY = 
event->fYRoot;
 
 3918       switch (fDragType) {
 
 3921             fSelectionIsOn = 
event->fState & kKeyShiftMask;
 
 3935    DrawGrabRectangles();
 
 3942 void TGuiBldDragManager::PlaceFrame(TGFrame *frame, TGLayoutHints *hints)
 
 3947    if (fStop || !frame || !fClient->IsEditable()) {
 
 3951    frame->MapSubwindows();
 
 3952    TGFrame *root = (TGFrame*)fClient->GetRoot();
 
 3954    gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(),
 
 3956                                    fPimpl->fX0 , fPimpl->fY0, x0, y0, c);
 
 3957    gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(),
 
 3959                                    fPimpl->fX , fPimpl->fY, x, y, c);
 
 3964    UInt_t w = TMath::Abs(x - x0);
 
 3965    UInt_t h = TMath::Abs(y - y0);
 
 3966    x = x > x0 ? x0 : x;
 
 3967    y = y > y0 ? y0 : y;
 
 3970    w = w < frame->GetDefaultWidth() + 2 ? frame->GetDefaultWidth() + 2 : w;
 
 3971    h = h < frame->GetDefaultHeight() + 2 ? frame->GetDefaultHeight() + 2 : h;
 
 3974    x = x + w > root->GetWidth() ? Int_t(root->GetWidth() - w) : x;
 
 3975    y = y + h > root->GetHeight() ? Int_t(root->GetHeight() - h) : y;
 
 3979    UInt_t grid = GetGridStep();
 
 3981    if (IsFixedW(frame) || IsFixedH(frame) || IsFixedSize(frame)) {
 
 3982       w = IsFixedW(frame) ? frame->GetDefaultWidth() : w;
 
 3983       h = IsFixedH(frame) ? frame->GetDefaultHeight() : h;
 
 3984       frame->Resize(w < grid ? grid : w, h < grid ? grid : h);
 
 3986       if (frame->InheritsFrom(TGVerticalFrame::Class())) {
 
 3987          frame->Resize(w < grid ? 15*grid : w, h < grid ?  30*grid : h);
 
 3988       } 
else if (frame->InheritsFrom(TGHorizontalFrame::Class())) {
 
 3989          frame->Resize(w < grid ? 30*grid : w, h < grid ?  15*grid : h);
 
 3991       else frame->Resize(w < 2*grid ? 2*grid : w, h < 2*grid ?  2*grid : h);
 
 3995    frame->SetCleanup(kDeepCleanup);
 
 3996    frame->AddInput(kButtonPressMask);
 
 3998    if (fClient->GetRoot()->InheritsFrom(TGCompositeFrame::Class())) {
 
 3999       TGCompositeFrame *edit = (TGCompositeFrame*)fClient->GetRoot();
 
 4000       edit->SetCleanup(kDeepCleanup);
 
 4001       ReparentFrames(frame, edit);
 
 4006       if (frame->InheritsFrom(
"TGStatusBar")) {
 
 4007          edit->AddFrame(frame, 
new TGLayoutHints(kLHintsBottom | kLHintsExpandX));
 
 4010          edit->AddFrame(frame, hints ? hints : 
new TGLayoutHints(kLHintsNormal, g, g, g, g));
 
 4013       if (hints && !edit->IsLayoutBroken()) {
 
 4014          edit->GetLayoutManager()->Layout();
 
 4020       TString str = frame->ClassName();
 
 4022       str += frame->GetName();
 
 4024       fBuilder->UpdateStatusBar(str.Data());
 
 4027    if (frame->InheritsFrom(TGCanvas::Class())) {
 
 4028       frame = ((TGCanvas*)frame)->GetContainer();
 
 4037 void TGuiBldDragManager::DrawLasso()
 
 4039    if (fStop || !fClient->IsEditable()) {
 
 4047    TGFrame *root = (TGFrame*)fClient->GetRoot();
 
 4049    gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(), root->GetId(),
 
 4050                                    fPimpl->fX0 , fPimpl->fY0, x0, y0, c);
 
 4051    gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(), root->GetId(),
 
 4052                                    fPimpl->fX , fPimpl->fY, x, y, c);
 
 4055    Bool_t xswap = kFALSE;
 
 4056    Bool_t yswap = kFALSE;
 
 4060    if ((x == x0) || ( y==y0 )) 
return; 
 
 4063       x0 = x0 < 0 ? 0 : x0;
 
 4073       y0 = y0 < 0 ? 0 : y0;
 
 4082    w = x0 + w > root->GetWidth() ? root->GetWidth() - x0 : w;
 
 4083    h = y0 + h > root->GetHeight() ? root->GetHeight() - y0 : h;
 
 4091    gVirtualX->TranslateCoordinates(root->GetId(), fClient->GetDefaultRoot()->GetId(),
 
 4092                                    xswap ? x : x0, yswap ? y : y0,
 
 4093                                    fPimpl->fX0 , fPimpl->fY0,  c);
 
 4094    gVirtualX->TranslateCoordinates(root->GetId(), fClient->GetDefaultRoot()->GetId(),
 
 4095                                    xswap ? x0 : x, yswap ? y0 : y,
 
 4096                                    fPimpl->fX , fPimpl->fY,  c);
 
 4099    gVirtualX->DrawRectangle(fClient->GetRoot()->GetId(),
 
 4100                             GetBlackGC()(), x0, y0, w, h);
 
 4101    gVirtualX->DrawRectangle(fClient->GetRoot()->GetId(),
 
 4102                             GetBlackGC()(), x0+1, y0+1, w-2, h-2);
 
 4104    gVirtualX->SetCursor(fId, gVirtualX->CreateCursor(kCross));
 
 4105    gVirtualX->SetCursor(fClient->GetRoot()->GetId(), gVirtualX->CreateCursor(kCross));
 
 4107    SetLassoDrawn(kTRUE);
 
 4108    root->RequestFocus();
 
 4111       TString str = 
"Lasso drawn. Align frames inside or presss Return key to grab frames.";
 
 4112       fBuilder->UpdateStatusBar(str.Data());
 
 4119 Bool_t TGuiBldDragManager::HandleClientMessage(Event_t *event)
 
 4125    if ((event->fFormat == 32) && ((Atom_t)event->fUser[0] == gWM_DELETE_WINDOW) &&
 
 4126        (event->fHandle != gROOT_MESSAGE)) {
 
 4128       if (fPimpl->fPlane && (fPimpl->fPlane->GetId() == 
event->fWindow)) {
 
 4132       TGWindow *root = (TGWindow*)fClient->GetRoot();
 
 4133       if (!root || (root == fClient->GetDefaultRoot())) {
 
 4134          SetEditable(kFALSE);
 
 4137       TGMainFrame *main = (TGMainFrame*)root->GetMainFrame();
 
 4139       if (event->fWindow == main->GetId()) {
 
 4140          if (main != fBuilder) {
 
 4141             if (fEditor && !fEditor->IsEmbedded()) {
 
 4146             SetEditable(kFALSE);
 
 4156          delete fPimpl->fGrid;
 
 4160       } 
else if (fBuilder && (event->fWindow == fBuilder->GetId())) {
 
 4161          fBuilder->CloseWindow();
 
 4163       } 
else if (fEditor && (event->fWindow == fEditor->GetMainFrame()->GetId())) {
 
 4164          TQObject::Disconnect(fEditor);
 
 4169       SetEditable(kFALSE);
 
 4178 Bool_t TGuiBldDragManager::HandleDestroyNotify(Event_t *event)
 
 4180    if (fPimpl->fPlane && (fPimpl->fPlane->GetId() == 
event->fWindow)) {
 
 4191 Bool_t TGuiBldDragManager::HandleSelection(Event_t *)
 
 4203 Bool_t TGuiBldDragManager::HandleSelectionRequest(Event_t *)
 
 4215 TGFrame *TGuiBldDragManager::GetMovableParent(TGWindow *p)
 
 4221    TGFrame *ret = (TGFrame*)p;
 
 4222    TGWindow *parent = (TGWindow*)ret->GetParent();
 
 4224    while (parent && (parent != fClient->GetDefaultRoot())) {
 
 4225       if (!IsFixedLayout(parent) && !IsEditDisabled(parent)) {
 
 4228       ret = (TGFrame*)parent;
 
 4229       parent = (TGWindow*)ret->GetParent();
 
 4238 TGWindow *TGuiBldDragManager::GetResizableParent(TGWindow *p)
 
 4244    TGWindow *parent = p;
 
 4246    while (parent && (parent != fClient->GetDefaultRoot())) {
 
 4247       if (!IsFixedSize(parent) &&
 
 4248           !IsFixedLayout((TGWindow*)parent->GetParent()) &&
 
 4249           !IsEditDisabled((TGWindow*)parent->GetParent())) {
 
 4252       parent = (TGWindow*)parent->GetParent();
 
 4261 Bool_t TGuiBldDragManager::StartDrag(TGFrame *src, Int_t x, Int_t y)
 
 4263    if (fStop || fDragging) {
 
 4270    if (fPimpl->fSpacePressedFrame) {
 
 4271       if (fDragType == kDragNone) {
 
 4272          fDragType = kDragMove;
 
 4273          mov = fPimpl->fSpacePressedFrame;
 
 4275          fPimpl->fSpacePressedFrame = 0;
 
 4279    TGWindow *parent = (TGWindow*)(mov ? mov->GetParent() : 0);
 
 4283    if (parent && (IsFixedLayout(parent) || IsEditDisabled(parent))) {
 
 4284       mov = GetMovableParent(parent);
 
 4294    fSelectionIsOn = kFALSE;
 
 4296    fPimpl->fRepeatTimer->Reset();
 
 4297    gSystem->AddTimer(fPimpl->fRepeatTimer);
 
 4299    fMoveWaiting = kFALSE;
 
 4301    if (src) gVirtualX->SetCursor(src->GetId(), gVirtualX->CreateCursor(kMove));
 
 4303    switch (fDragType) {
 
 4307          GrabFrame(fPimpl->fGrab);
 
 4310          fPimpl->fGrab = mov;
 
 4311          GrabFrame(fPimpl->fGrab);
 
 4324 Bool_t TGuiBldDragManager::EndDrag()
 
 4327    Bool_t ret = kFALSE;
 
 4333    fMoveWaiting = kFALSE;  
 
 4335    if (fPimpl->fGrab && (fDragType >= kDragMove) && (fDragType <= kDragLink)) {
 
 4339    } 
else if (fBuilder && fBuilder->IsExecutable() &&
 
 4340               (fDragType == kDragLasso) && !fSelectionIsOn) {
 
 4342       frame = (TGFrame*)fBuilder->ExecuteAction();
 
 4343       PlaceFrame(frame, fBuilder->GetAction()->fHints);
 
 4344       SetLassoDrawn(kFALSE);
 
 4347    } 
else if ((fDragType == kDragLasso) && fSelectionIsOn) {
 
 4349       HandleReturn(kFALSE);
 
 4358    fPimpl->fSpacePressedFrame = 0;
 
 4361       fBuilder->SetAction(0);
 
 4370 Bool_t TGuiBldDragManager::Cancel(Bool_t )
 
 4384 Bool_t TGuiBldDragManager::Drop()
 
 4386    if (fStop || !fDragging || !fPimpl->fGrab ||
 
 4387        !((fDragType >= kDragMove) && (fDragType <= kDragLink))) {
 
 4391    fDropStatus = kFALSE;
 
 4393    TGFrame *parent = 0;
 
 4397    switch (fDragType) {
 
 4400          frame = (TGFrame*)fPimpl->fGrab;
 
 4406    TGWindow *w = fClient->GetWindowById(fTargetId);
 
 4408    if (fTarget && fPimpl->fGrab && (w == fTarget) &&  w &&
 
 4409        (w != fClient->GetDefaultRoot())) {
 
 4412       gVirtualX->TranslateCoordinates(fClient->GetDefaultRoot()->GetId(),
 
 4414                                       fPimpl->fGrab->GetX(),
 
 4415                                       fPimpl->fGrab->GetY(), x, y, c);
 
 4416       fTarget->HandleDragLeave(fPimpl->fGrab);
 
 4418       parent = (TGFrame*)fPimpl->fGrabParent;
 
 4424    if (parent && !parent->IsLayoutBroken() && (parent == fPimpl->fGrabParent) ) {
 
 4426    } 
else if (parent && frame && (parent != fClient->GetDefaultRoot()) ) {
 
 4428       fDropStatus = parent->HandleDragDrop(frame, x, y, fPimpl->fGrabLayout);
 
 4432          if (fDragType == kDragMove) {  
 
 4433             parent = (TGFrame*)fPimpl->fGrabParent;
 
 4436             frame = fPimpl->fGrab;
 
 4438             if (parent && frame && (parent != fClient->GetDefaultRoot())) {
 
 4439                fDropStatus = parent->HandleDragDrop(frame, x, y, fPimpl->fGrabLayout);
 
 4449       if (parent && !parent->IsLayoutBroken()) {
 
 4454          TString str = frame->ClassName();
 
 4456          str += frame->GetName();
 
 4457          str += 
" dropped into ";
 
 4458          str += parent->ClassName();
 
 4460          str += parent->GetName();
 
 4461          str += 
" at position  ";
 
 4462          str += TString::Format(
"(%d , %d)", x, y);
 
 4463          fBuilder->UpdateStatusBar(str.Data());
 
 4468       if (parent && (parent == fPimpl->fGrabParent) && fPimpl->fGrabListPosition &&
 
 4469           frame && parent->InheritsFrom(TGCompositeFrame::Class())) {
 
 4471          TList *li = ((TGCompositeFrame*)parent)->GetList();
 
 4472          li->Remove(frame->GetFrameElement());
 
 4473          li->AddAfter(fPimpl->fGrabListPosition, frame->GetFrameElement());
 
 4480       if (fPimpl->fGrab && fPimpl->fGrabParent) {
 
 4481          fPimpl->fGrab->ReparentWindow(fPimpl->fGrabParent, fPimpl->fGrabX, fPimpl->fGrabY);
 
 4482          ((TGCompositeFrame*)fPimpl->fGrabParent)->AddFrame(fPimpl->fGrab);
 
 4486    fPimpl->fGrabParent = 0;
 
 4489    fPimpl->fGrabListPosition = 0;
 
 4501 Bool_t TGuiBldDragManager::IsMoveWaiting()
 const 
 4503    return fMoveWaiting;
 
 4511 void TGuiBldDragManager::Compact(Bool_t global)
 
 4513    TGCompositeFrame *comp = 0;
 
 4516    if (fStop || !fClient || !fClient->IsEditable() || !fPimpl->fGrab) {
 
 4520    TGWindow *parent = (TGWindow*)fPimpl->fGrab->GetParent();
 
 4524          comp = (TGCompositeFrame*)fClient->GetRoot()->GetMainFrame();
 
 4526          comp = fBuilder->FindEditableMdiFrame(fClient->GetRoot());
 
 4528             comp = (TGCompositeFrame*)fClient->GetRoot()->GetMainFrame();
 
 4532       if (fPimpl->fGrab &&
 
 4533           fPimpl->fGrab->InheritsFrom(TGCompositeFrame::Class())) {
 
 4534          comp = (TGCompositeFrame*)fPimpl->fGrab;
 
 4536          comp = (TGCompositeFrame*)parent;
 
 4540    if (!comp || IsFixedLayout(comp)  || IsFixedLayout(parent) ||
 
 4541        IsFixedSize(comp) || IsFixedH(comp) || IsFixedW(comp)) 
return;
 
 4543    comp->SetLayoutBroken(kFALSE);
 
 4545    TIter next(comp->GetList());
 
 4547    TGFrame *root = (TGFrame *)fClient->GetRoot();
 
 4548    root->SetEditable(kFALSE);
 
 4553       while ((fe = (TGFrameElement*)next())) {
 
 4554          if (IsFixedLayout(fe->fFrame) || IsFixedSize(fe->fFrame) ||
 
 4555              IsFixedH(fe->fFrame) || IsFixedW(fe->fFrame)) 
continue;
 
 4557          fe->fFrame->SetLayoutBroken(kFALSE);
 
 4558          d = fe->fFrame->GetDefaultSize();
 
 4561          if ((d.fWidth > 10) && (d.fHeight > 10)) {
 
 4562             fe->fFrame->Resize();
 
 4563          } 
else if (d.fWidth > 10) {
 
 4564             fe->fFrame->Resize(d.fWidth, 10);
 
 4565          } 
else if (d.fHeight > 10) {
 
 4566             fe->fFrame->Resize(10, d.fHeight);
 
 4568             fe->fFrame->Resize(10, 10);
 
 4570          fClient->NeedRedraw(fe->fFrame);
 
 4572       if (!IsFixedLayout(root)) {
 
 4573          root->SetLayoutBroken(kFALSE);
 
 4575       fPimpl->fCompacted = kTRUE;
 
 4578    if (!IsFixedLayout(comp)) {
 
 4579       comp->SetLayoutBroken(kFALSE);
 
 4580       d = comp->GetDefaultSize();
 
 4583       if ((d.fWidth > 10) && (d.fHeight > 10)) {
 
 4585       } 
else if (d.fWidth > 10) {
 
 4586          comp->Resize(d.fWidth, 10);
 
 4587       } 
else if (d.fHeight > 10) {
 
 4588          comp->Resize(10, d.fHeight);
 
 4590          comp->Resize(10, 10);
 
 4595    if (comp->GetParent()->InheritsFrom(TGMdiDecorFrame::Class())) {
 
 4596       TGMdiDecorFrame *decor = (TGMdiDecorFrame *)comp->GetParent();
 
 4597       Int_t b = 2 * decor->GetBorderWidth();
 
 4598       decor->MoveResize(decor->GetX(), decor->GetY(), comp->GetDefaultWidth() + b,
 
 4599                         comp->GetDefaultHeight() + b + decor->GetTitleBar()->GetDefaultHeight());
 
 4602    root->SetEditable(kTRUE);
 
 4604    fClient->NeedRedraw(comp);
 
 4612 void TGuiBldDragManager::SetEditable(Bool_t on)
 
 4614    static Bool_t gon = kFALSE;
 
 4615    static const TGWindow *gw = 0;
 
 4617    if ((gon == on) && (fClient->GetRoot() == gw)) {
 
 4621    gon = on;  gw = fClient->GetRoot();
 
 4626       if (fPimpl->fRepeatTimer) {
 
 4627          fPimpl->fRepeatTimer->Reset();
 
 4629          fPimpl->fRepeatTimer = 
new TGuiBldDragManagerRepeatTimer(
this, 100);
 
 4631       gSystem->AddTimer(fPimpl->fRepeatTimer);
 
 4632       ((TGFrame*)fClient->GetRoot())->AddInput(kKeyPressMask | kButtonPressMask);
 
 4636       HideGrabRectangles();
 
 4638       if (fPimpl->fRepeatTimer) {
 
 4639          fPimpl->fRepeatTimer->Remove();
 
 4642       fSelected = fPimpl->fGrab = 0;
 
 4644       delete fPimpl->fGrid;
 
 4647       fPimpl->ResetParams();
 
 4649       TGWindow *root = (TGWindow*)fClient->GetRoot();
 
 4651          fClient->SetRoot(0);
 
 4654       if (!gSystem->AccessPathName(fPasteFileName.Data())) {
 
 4655          gSystem->Unlink(fPasteFileName.Data());
 
 4658       if (!gSystem->AccessPathName(fTmpBuildFile.Data())) {
 
 4659          gSystem->Unlink(fTmpBuildFile.Data());
 
 4670    if (on && fClient->IsEditable()) {
 
 4671       gVirtualX->SetCursor(fClient->GetRoot()->GetId(),
 
 4672                            gVirtualX->CreateCursor(kPointer));
 
 4679 void TGuiBldDragManager::ToGrid(Int_t &x, Int_t &y)
 
 4681    UInt_t step = GetGridStep();
 
 4689 void TGuiBldDragManager::HandleAction(Int_t act)
 
 4691    fPimpl->fLastPopupAction = act;
 
 4693    switch ((EActionType)act) {
 
 4695          CreatePropertyEditor();
 
 4698          if (fPimpl->fSaveGrab) fPimpl->fSaveGrab->SetEditable(kTRUE);
 
 4700             fBuilder->HandleMenu(kGUIBLD_FILE_START);
 
 4713          HandleDelete(kTRUE);
 
 4718       case kCompactGlobalAct:
 
 4722          HandleReturn(kTRUE);
 
 4725          HandleLayoutOrder(kFALSE);
 
 4728          HandleLayoutOrder(kTRUE);
 
 4734          HandleReturn(kFALSE);
 
 4737          HandleDelete(kFALSE);
 
 4740          HandleAlignment(kKey_Left);
 
 4743          HandleAlignment(kKey_Right);
 
 4746          HandleAlignment(kKey_Up);
 
 4749          HandleAlignment(kKey_Down);
 
 4753             fBuilder->HandleMenu(kGUIBLD_FILE_STOP);
 
 4755          SetEditable(kFALSE);
 
 4763       case kBreakLayoutAct:
 
 4766       case kSwitchLayoutAct:
 
 4773             fBuilder->NewProject();
 
 4775             TGMainFrame *main = 
new TGMainFrame(fClient->GetDefaultRoot(), 300, 300);
 
 4777             main->SetEditable(kTRUE);
 
 4782             fBuilder->OpenProject();
 
 4784             TGMainFrame *main = 
new TGMainFrame(fClient->GetDefaultRoot(), 300, 300);
 
 4786             main->SetEditable(kTRUE);
 
 4791             if (fBuilder->FindEditableMdiFrame(fClient->GetRoot()) ||
 
 4792                 (!fClient->IsEditable() && fBuilder->GetMdiMain()->GetCurrent())) {
 
 4793                fBuilder->SaveProject();
 
 4808    fPimpl->fPlacePopup = kFALSE;
 
 4811       fBuilder->SetAction(0);
 
 4815    if (fPimpl->fSaveGrab) {
 
 4816       fClient->NeedRedraw(fPimpl->fSaveGrab, kTRUE);
 
 4825 Bool_t TGuiBldDragManager::CanChangeLayout(TGWindow *w)
 const 
 4827    return (!(w->GetEditDisabled() & kEditDisable) &&
 
 4828            !IsFixedLayout(w) && w->InheritsFrom(TGCompositeFrame::Class()));
 
 4834 Bool_t TGuiBldDragManager::CanChangeLayoutOrder(TGWindow *w)
 const 
 4836    return (w->GetParent()->InheritsFrom(TGCompositeFrame::Class()) &&
 
 4837            !((TGCompositeFrame*)w->GetParent())->IsLayoutBroken() &&
 
 4838            !IsFixedLayout((TGWindow*)w->GetParent()));
 
 4844 Bool_t TGuiBldDragManager::CanCompact(TGWindow *w)
 const 
 4846    return CanChangeLayout(w);
 
 4859 void TGuiBldDragManager::CreatePropertyEditor()
 
 4863    TGWindow *root = (TGWindow*)fClient->GetRoot();
 
 4864    root->SetEditable(kFALSE);
 
 4866    fBuilder = (TRootGuiBuilder*)TRootGuiBuilder::Instance();
 
 4868    fBuilder->Move(fPimpl->fX0, fPimpl->fY0);
 
 4869    fBuilder->SetWMPosition(fPimpl->fX0, fPimpl->fY0);
 
 4870    SetPropertyEditor(fBuilder->GetEditor());
 
 4872    root->SetEditable(kTRUE);
 
 4878 void TGuiBldDragManager::SetPropertyEditor(TGuiBldEditor *e)
 
 4886    ChangeSelected(fPimpl->fClickFrame);
 
 4887    fEditor->Connect(
"UpdateSelected(TGFrame*)", 
"TGuiBldDragManager", 
this,
 
 4888                     "HandleUpdateSelected(TGFrame*)");
 
 4894 void TGuiBldDragManager::HandleLayoutOrder(Bool_t forward)
 
 4896    if (fStop || !fPimpl->fGrab || !fPimpl->fGrab->GetFrameElement() ||
 
 4897        !CanChangeLayoutOrder(fPimpl->fGrab)) {
 
 4901    TGCompositeFrame *comp = (TGCompositeFrame*)fPimpl->fGrab->GetParent();
 
 4902    TList *li = comp->GetList();
 
 4903    TGFrameElement *fe = fPimpl->fGrab->GetFrameElement();
 
 4913       el = (TGFrameElement *)li->After(fe);
 
 4917       el->fFrame = fPimpl->fGrab;
 
 4918       fPimpl->fGrab->SetFrameElement(el);
 
 4920       frame->SetFrameElement(fe);
 
 4922       el = (TGFrameElement *)li->Before(fe);
 
 4929       el->fFrame = fPimpl->fGrab;
 
 4930       fPimpl->fGrab->SetFrameElement(el);
 
 4932       frame->SetFrameElement(fe);
 
 4935    Bool_t sav = comp->IsLayoutBroken();
 
 4936    comp->SetLayoutBroken(kFALSE);
 
 4937    TGWindow *root = (TGWindow *)fClient->GetRoot();
 
 4938    root->SetEditable(kFALSE);
 
 4941    root->SetEditable(kTRUE);
 
 4944       comp->SetLayoutBroken(kTRUE);
 
 4946    SelectFrame(el->fFrame);
 
 4952 void TGuiBldDragManager::HandleGrid()
 
 4958    TGWindow *root = (TGWindow*)fClient->GetRoot();
 
 4960    if (!root || (root == fClient->GetDefaultRoot())) {
 
 4964    if (fPimpl->fGrid->fgStep > 1) {
 
 4965       fPimpl->fGrid->SetStep(1);
 
 4967          fBuilder->UpdateStatusBar(
"Grid switched OFF");
 
 4970       fPimpl->fGrid->SetStep(gGridStep);
 
 4973          fBuilder->UpdateStatusBar(
"Grid switched ON");
 
 4976       if (root->InheritsFrom(TGCompositeFrame::Class())) {
 
 4977          TGCompositeFrame *comp = (TGCompositeFrame*)root;
 
 4978          TIter next(comp->GetList());
 
 4982          while ((fe = (TGFrameElement*)next())) {
 
 4983             x = fe->fFrame->GetX();
 
 4984             y = fe->fFrame->GetY();
 
 4985             w = fe->fFrame->GetWidth();
 
 4986             h = fe->fFrame->GetHeight();
 
 4989             fe->fFrame->MoveResize(x, y, w, h);
 
 4995    DrawGrabRectangles();
 
 5001 TGCompositeFrame *TGuiBldDragManager::FindLayoutFrame(TGFrame *f)
 
 5007    const TGWindow *parent = f->GetParent();
 
 5008    TGCompositeFrame *ret = 0;
 
 5010    while (parent && (parent != fClient->GetDefaultRoot())) {
 
 5011       ret = (TGCompositeFrame*)parent;
 
 5012       if (parent->InheritsFrom(TGMdiFrame::Class())) 
return ret;
 
 5013       parent = parent->GetParent();
 
 5021 void TGuiBldDragManager::HandleUpdateSelected(TGFrame *f)
 
 5027    TGCompositeFrame *parent = 0;
 
 5028    if (f->GetParent() &&
 
 5029        f->GetParent()->InheritsFrom(TGCompositeFrame::Class())) {
 
 5030       parent = (TGCompositeFrame*)f->GetParent();
 
 5033    if (!parent || !CanChangeLayout(parent)) {
 
 5037    Bool_t sav = parent->IsLayoutBroken();
 
 5038    parent->SetLayoutBroken(kFALSE);
 
 5040    if ((parent->GetWidth() < parent->GetDefaultWidth()) ||
 
 5041         (parent->GetHeight() < parent->GetDefaultHeight())) {
 
 5042       parent->Resize(parent->GetDefaultSize());
 
 5045       if (f->InheritsFrom(TGCompositeFrame::Class())) {
 
 5049    fClient->NeedRedraw(parent, kTRUE);
 
 5050    fClient->NeedRedraw(f);
 
 5052    if (sav) parent->SetLayoutBroken(kTRUE);
 
 5060 void TGuiBldDragManager::HideGrabRectangles()
 
 5062    static Bool_t first = kFALSE;
 
 5064    if (fPimpl->fGrabRectHidden) {
 
 5073    for (i = 0; i < 8; i++) fPimpl->fGrabRect[i]->UnmapWindow();
 
 5074    for (i = 0; i < 4; i++) fPimpl->fAroundFrame[i]->UnmapWindow();
 
 5075    fPimpl->fGrabRectHidden = kTRUE;
 
 5081 void TGuiBldDragManager::DeletePropertyEditor()
 
 5083    if (fStop || !fEditor) {
 
 5087    TQObject::Disconnect(fEditor);
 
 5096 Int_t TGuiBldDragManager::GetStrartDragX()
 const 
 5104 Int_t TGuiBldDragManager::GetStrartDragY()
 const 
 5112 Int_t TGuiBldDragManager::GetEndDragX()
 const 
 5120 Int_t TGuiBldDragManager::GetEndDragY()
 const 
 5128 void TGuiBldDragManager::BreakLayout()
 
 5134    TGFrame *frame = fSelected;
 
 5140    TString str = frame->ClassName();
 
 5142    str += frame->GetName();
 
 5144    if (IsFixedLayout(frame)) {
 
 5146          str += 
" layout cannot be broken";
 
 5147          fBuilder->UpdateStatusBar(str.Data());
 
 5152    frame->SetLayoutBroken(!frame->IsLayoutBroken());
 
 5153    DrawGrabRectangles();
 
 5156       str += (frame->IsLayoutBroken() ? 
" Disable Layout" : 
" Enable Layout");
 
 5157       fBuilder->UpdateStatusBar(str.Data());
 
 5159    if (fPimpl->fGrab && (fPimpl->fGrab->IsA() == TGCanvas::Class())) {
 
 5160       fPimpl->fGrab->Layout();
 
 5167 void TGuiBldDragManager::SwitchLayout()
 
 5169    if (fStop || !fPimpl->fGrab) {
 
 5173    TGCompositeFrame *comp = (TGCompositeFrame*)fSelected;
 
 5175    comp->SetLayoutBroken(kFALSE);
 
 5177    UInt_t opt = comp->GetOptions();
 
 5178    TGLayoutManager *m = comp->GetLayoutManager();
 
 5184    if (m->InheritsFrom(TGHorizontalLayout::Class())) {
 
 5185       opt &= ~kHorizontalFrame;
 
 5186       opt |= kVerticalFrame;
 
 5189          TString str = comp->ClassName();
 
 5191          str += comp->GetName();
 
 5192          str += 
" Vertical Layout ON";
 
 5193          fBuilder->UpdateStatusBar(str.Data());
 
 5195    } 
else if (m->InheritsFrom(TGVerticalLayout::Class())) {
 
 5196       opt &= ~kVerticalFrame;
 
 5197       opt |= kHorizontalFrame;
 
 5200          TString str = comp->ClassName();
 
 5202          str += comp->GetName();
 
 5203          str += 
" Horizontal Layout ON";
 
 5204          fBuilder->UpdateStatusBar(str.Data());
 
 5208    comp->ChangeOptions(opt);
 
 5209    if (!IsFixedSize(comp)) {
 
 5213    if (fPimpl->fGrab && (fPimpl->fGrab->IsA() == TGCanvas::Class())) {
 
 5214       fPimpl->fGrab->Layout();
 
 5217    fClient->NeedRedraw(comp);
 
 5224 TGFrame *TGuiBldDragManager::GetSelected()
 const 
 5232 void TGuiBldDragManager::CloseMenus()
 
 5237       fFrameMenu->EndMenu(ud);
 
 5240       fLassoMenu->EndMenu(ud);
 
 5248 TGFrame *TGuiBldDragManager::GetEditableParent(TGFrame *fr)
 
 5250    if (!fr || (fr == fClient->GetDefaultRoot())) {
 
 5254    TGWindow *parent = (TGWindow*)fr->GetParent();
 
 5256    while (parent && (parent != fClient->GetDefaultRoot())) {
 
 5257       if (!IsEditDisabled(parent) && !IsGrabDisabled(parent)) {
 
 5258          return (TGFrame*)parent;
 
 5260       parent = (TGWindow*)parent->GetParent();
 
 5268 static TString FindMenuIconName(TString &in)
 
 5270    Int_t p1 = in.Index(
"*icon=", 1);
 
 5271    if (p1 == kNPOS) 
return "";
 
 5273    Int_t p2 = in.Index(
"*", p1);
 
 5275    if (p2 == kNPOS) 
return "";
 
 5277    return in(p1, p2-p1);
 
 5283 static Bool_t containBaseClass(
const char *somestring, TClass *cl)
 
 5285    TString str = somestring;
 
 5287    if (str.Contains(cl->GetName())) {
 
 5291    TIter nextBaseClass(cl->GetListOfBases());
 
 5294    while ((bc = (TBaseClass*)nextBaseClass())) {
 
 5295       if (!bc->GetClassPointer()) {
 
 5298       if (containBaseClass(somestring, bc->GetClassPointer())) {
 
 5309 void TGuiBldDragManager::AddDialogMethods(TGPopupMenu *menu, TObject *
object)
 
 5311    if (!menu || !
object) {
 
 5316    TIter next(fListOfDialogs);
 
 5319    const TGPicture *pic;
 
 5320    TClass *cl = 
object->IsA();
 
 5323    while ((method = (TMethod*) next())) {
 
 5324       ename = method->GetName();
 
 5326       if (menu->GetEntry(ename.Data())) {
 
 5329       if (!containBaseClass(method->GetSignature(), cl)) {
 
 5333       str = method->GetCommentString();
 
 5334       pname = FindMenuIconName(str);
 
 5335       pic = fClient->GetPicture(pname.Data());
 
 5336       menu->AddEntry(ename.Data(), kMethodMenuAct, method, pic);
 
 5338    menu->AddSeparator();
 
 5344 void TGuiBldDragManager::AddClassMenuMethods(TGPopupMenu *menu, TObject *
object)
 
 5346    if (!menu || !
object) {
 
 5350    TList *menuItemList;
 
 5351    TClassMenuItem *menuItem;
 
 5354    const TGPicture *pic;
 
 5356    TClass   *classPtr = 0;
 
 5358    EMenuItemKind menuKind;
 
 5361    AddDialogMethods(menu, 
object);
 
 5363    menuItemList = 
object->IsA()->GetMenuList();
 
 5364    TIter nextItem(menuItemList);
 
 5366    fPimpl->fMenuObject = (TGFrame*)
object;
 
 5369    while ((menuItem = (TClassMenuItem*) nextItem())) {
 
 5370       switch (menuItem->GetType()) {
 
 5371          case TClassMenuItem::kPopupStandardList:
 
 5376                methodList = 
new TList;
 
 5377                object->IsA()->GetMenuItems(methodList);
 
 5379                TIter next(methodList);
 
 5381                while ((method = (TMethod*) next())) {
 
 5382                   if (classPtr != method->GetClass()) {
 
 5384                      classPtr = method->GetClass();
 
 5387                   menuKind = method->IsMenuItem();
 
 5392                         str = method->GetCommentString();
 
 5393                         pname = FindMenuIconName(str);
 
 5394                         pic = fClient->GetPicture(pname.Data());
 
 5395                         menu->AddEntry(method->GetName(), kMethodMenuAct, method, pic);
 
 5400                         if ((m = method->FindDataMember())) {
 
 5401                            if (m->GetterMethod()) {
 
 5402                               TGPopupMenu *r = TRootGuiBuilder::CreatePopup();
 
 5403                               menu->AddPopup(method->GetName(), r);
 
 5404                               fPimpl->fFrameMenuTrash->Add(r);
 
 5405                               TIter nxt(m->GetOptions());
 
 5406                               TOptionListItem *it;
 
 5408                               while ((it = (TOptionListItem*) nxt())) {
 
 5409                                  const char  *name  = it->fOptName;
 
 5410                                  Long_t val   = it->fValue;
 
 5412                                  TToggle *t = 
new TToggle;
 
 5413                                  t->SetToggledObject(
object, method);
 
 5415                                  fPimpl->fFrameMenuTrash->Add(t);
 
 5418                                  r->AddEntry(name, kToggleMenuAct, t);
 
 5419                                  if (t->GetState()) r->CheckEntryByData(t);
 
 5422                               menu->AddEntry(method->GetName(), kMethodMenuAct, method);
 
 5429                            TToggle *t = 
new TToggle;
 
 5430                            t->SetToggledObject(
object, method);
 
 5432                            fPimpl->fFrameMenuTrash->Add(t);
 
 5433                            menu->AddEntry(method->GetName(), kToggleMenuAct, t);
 
 5434                            if (t->GetState()) menu->CheckEntryByData(t);
 
 5445          case TClassMenuItem::kPopupUserFunction:
 
 5447                if (menuItem->IsToggle()) {
 
 5449                         object->IsA()->GetMethodWithPrototype(menuItem->GetFunctionName(),
 
 5450                                                               menuItem->GetArgs());
 
 5452                      TToggle *t = 
new TToggle;
 
 5453                      t->SetToggledObject(
object, method2);
 
 5455                      fPimpl->fFrameMenuTrash->Add(t);
 
 5457                      menu->AddEntry(method2->GetName(), kToggleMenuAct, t);
 
 5458                      if (t->GetState()) menu->CheckEntryByData(t);
 
 5461                   const char* menuItemTitle = menuItem->GetTitle();
 
 5462                   if (strlen(menuItemTitle)==0) menuItemTitle = menuItem->GetFunctionName();
 
 5463                   menu->AddEntry(menuItemTitle, kMethodMenuAct, menuItem);
 
 5477 void TGuiBldDragManager::DoClassMenu(Int_t 
id)
 
 5479    if (!fFrameMenu || ((
id != kMethodMenuAct) && (
id != kToggleMenuAct))) {
 
 5483    TGMenuEntry *me = 0;
 
 5485    if (
id == kMethodMenuAct) {
 
 5487       me = fFrameMenu->GetCurrent();
 
 5489       if (!me || !fPimpl->fMenuObject) {
 
 5492       TMethod *method = (TMethod*)me->GetUserData();
 
 5493       TString str = method->GetCommentString();
 
 5495       if (str.Contains(
"*DIALOG")) {
 
 5497          str2.Form(
"((TGuiBldDragManager*)0x%lx)->%s((%s*)0x%lx)", (ULong_t)
this, method->GetName(),
 
 5498                   fPimpl->fMenuObject->ClassName(), (ULong_t)fPimpl->fMenuObject);
 
 5499          gCling->Calc((
char *)str2.Data());
 
 5504       gMenuDialog = 
new TGuiBldMenuDialog(fPimpl->fMenuObject, fPimpl->fMenuObject, method);
 
 5505       gMenuDialog->Popup();
 
 5507    } 
else if (
id == kToggleMenuAct) {
 
 5508       me = fFrameMenu->GetCurrent();
 
 5512       TGPopupMenu *menu = me->GetPopup();
 
 5513       TToggle *toggle = 0;
 
 5516          toggle = (TToggle*)menu->GetCurrent()->GetUserData();
 
 5518          toggle = (TToggle*)fFrameMenu->GetCurrent()->GetUserData();
 
 5529 void TGuiBldDragManager::DeleteMenuDialog()
 
 5531    fPimpl->fFrameMenuTrash->Delete();
 
 5532    gMenuDialog->DeleteWindow();
 
 5534    fPimpl->fMenuObject = 0;
 
 5540 void TGuiBldDragManager::DoDialogOK()
 
 5542    gMenuDialog->ApplyMethod();
 
 5551 void TGuiBldDragManager::DoDialogApply()
 
 5553    gMenuDialog->ApplyMethod();
 
 5559 void TGuiBldDragManager::DoDialogCancel()
 
 5568 void TGuiBldDragManager::Menu4Frame(TGFrame *frame, Int_t x, Int_t y)
 
 5574    fPimpl->fSaveGrab = fPimpl->fGrab;
 
 5577    fPimpl->fClickFrame = frame;
 
 5579    Bool_t composite = frame->InheritsFrom(TGCompositeFrame::Class());
 
 5580    Bool_t compar = frame->GetParent()->InheritsFrom(TGCompositeFrame::Class());
 
 5582    TGCompositeFrame *cfr = 0;
 
 5583    TGCompositeFrame *cfrp = 0;
 
 5584    TGLayoutManager *lm = 0;
 
 5587       cfr = (TGCompositeFrame *)frame;
 
 5588       lm = cfr->GetLayoutManager();
 
 5591       cfrp = (TGCompositeFrame *)frame->GetParent();
 
 5596    fFrameMenu = TRootGuiBuilder::CreatePopup();
 
 5597    fFrameMenu->Connect(
"Activated(Int_t)", 
"TGuiBldDragManager", 
this, 
"DoClassMenu(Int_t)");
 
 5599    TString title = frame->ClassName();
 
 5601    title += frame->GetName();
 
 5602    fFrameMenu->AddLabel(title.Data());
 
 5603    fFrameMenu->AddSeparator();
 
 5606    if (fBuilder && (frame == fBuilder->GetMdiMain()->GetCurrent())) {
 
 5607       if (!gSystem->AccessPathName(fPasteFileName.Data())) {
 
 5608          fFrameMenu->AddEntry(
"Paste\tCtrl+V", kPasteAct,
 
 5609                                0, fClient->GetPicture(
"bld_paste.png"));
 
 5611       fFrameMenu->AddEntry(
"Compact\tCtrl+L", kCompactAct,
 
 5612                                0, fClient->GetPicture(
"bld_compact.png"));
 
 5613       fFrameMenu->AddEntry(
"Grid On/Off\tCtrl+G", kGridAct,
 
 5614                               0, fClient->GetPicture(
"bld_grid.png"));
 
 5615       fFrameMenu->AddEntry(
"Save As ...\tCtrl+S", kSaveAct,
 
 5616                               0, fClient->GetPicture(
"bld_save.png"));
 
 5617       fFrameMenu->AddEntry(
"End Edit\tCtrl+DblClick", kEndEditAct,
 
 5618                               0, fClient->GetPicture(
"bld_stop.png"));
 
 5622    AddClassMenuMethods(fFrameMenu, frame);
 
 5625       fFrameMenu->AddEntry(
"Gui Builder", kPropertyAct);
 
 5626       fFrameMenu->AddSeparator();
 
 5634    if (!IsEditDisabled(cfrp)) {
 
 5635       fFrameMenu->AddSeparator();
 
 5637       if (composite && !IsFixedLayout(frame) && cfr->GetList()->GetEntries()) {
 
 5638          fFrameMenu->AddEntry(
"Drop\tCtrl+Return", kDropAct);
 
 5641       if (!IsFixedLayout(cfrp)) {
 
 5642          fFrameMenu->AddEntry(
"Cut\tCtrl+X", kCutAct,
 
 5643                                0, fClient->GetPicture(
"bld_cut.png"));
 
 5646       fFrameMenu->AddEntry(
"Copy\tCtrl+C", kCopyAct,
 
 5647                             0, fClient->GetPicture(
"bld_copy.png"));
 
 5649       if (frame->IsEditable() && !IsFixedLayout(frame) &&
 
 5650           !gSystem->AccessPathName(fPasteFileName.Data())) {
 
 5651          fFrameMenu->AddEntry(
"Paste\tCtrl+V", kPasteAct,
 
 5652                                0, fClient->GetPicture(
"bld_paste.png"));
 
 5655       if (!IsFixedLayout(cfrp)) {
 
 5656          fFrameMenu->AddEntry(
"Delete\tDel", kDeleteAct,
 
 5657                               0, fClient->GetPicture(
"bld_delete.png"));
 
 5660       if (!IsFixedLayout(cfrp)) {
 
 5661          fFrameMenu->AddEntry(
"Crop\tShift+Del", kCropAct,
 
 5662                                0, fClient->GetPicture(
"bld_crop.png"));
 
 5670       fFrameMenu->AddSeparator();
 
 5672       if (!gSystem->AccessPathName(fPasteFileName.Data()) && !IsFixedLayout(frame)) {
 
 5673          fFrameMenu->AddEntry(
"Paste\tCtrl+V", kPasteAct,
 
 5674                                0, fClient->GetPicture(
"bld_paste.png"));
 
 5676       if (frame->GetMainFrame() == frame) {
 
 5677          fFrameMenu->AddEntry(
"Clone\tCtrl+A", kCloneAct);
 
 5679       fFrameMenu->AddSeparator();
 
 5682    if (CanChangeLayout(frame)) {
 
 5683       const char *label = (frame->IsLayoutBroken() ? 
"Allow Layout\tCtrl+B" :
 
 5684                                                      "Break Layout\tCtrl+B");
 
 5685       fFrameMenu->AddEntry(label, kBreakLayoutAct,
 
 5686                             0, fClient->GetPicture(
"bld_break.png"));
 
 5689    if (composite && !cfr->GetList()->IsEmpty()) {
 
 5690       if (CanCompact(frame)) {
 
 5691          if (!frame->IsEditable()) {
 
 5692             fFrameMenu->AddEntry(
"Compact\tCtrl+L", kCompactAct,
 
 5693                                   0, fClient->GetPicture(
"bld_compact.png"));
 
 5695             fFrameMenu->AddEntry(
"Compact\tCtrl+L", kCompactGlobalAct,
 
 5696                                   0, fClient->GetPicture(
"bld_compact.png"));
 
 5700       if (lm && ((lm->IsA() == TGVerticalLayout::Class()) ||
 
 5701            (lm->IsA() == TGHorizontalLayout::Class())) && !IsFixedLayout(frame)) {
 
 5703          if (lm->IsA() == TGVerticalLayout::Class()) {
 
 5704             fFrameMenu->AddEntry(
"Horizontal\tCtrl+H", kSwitchLayoutAct,
 
 5705                                  0, fClient->GetPicture(
"bld_hbox.png"));
 
 5706          } 
else if (lm->IsA() == TGHorizontalLayout::Class()) {
 
 5707             fFrameMenu->AddEntry(
"Vertical\tCtrl+H", kSwitchLayoutAct,
 
 5708                                  0, fClient->GetPicture(
"bld_vbox.png"));
 
 5713    if (compar && (cfrp->GetList()->GetSize() > 1) && CanChangeLayoutOrder(frame)) {
 
 5714       if (cfrp->GetList()->First() != frame->GetFrameElement()) {
 
 5715          fFrameMenu->AddEntry(
"Lay Up\tUp/Left", kLayUpAct);
 
 5717       if (cfrp->GetList()->Last() != frame->GetFrameElement()) {
 
 5718          fFrameMenu->AddEntry(
"Lay Down\tDown/Right", kLayDownAct);
 
 5720       fFrameMenu->AddSeparator();
 
 5723    if (frame->IsEditable()) {
 
 5724       fFrameMenu->AddEntry(
"Grid On/Off\tCtrl+G", kGridAct,
 
 5725                             0, fClient->GetPicture(
"bld_grid.png"));
 
 5727    if (composite && !cfr->GetList()->IsEmpty()) {
 
 5728       fPimpl->fSaveGrab = frame;
 
 5729       fFrameMenu->AddEntry(
"Save As ...       ", kSaveFrameAct,
 
 5730                             0, fClient->GetPicture(
"bld_save.png"));
 
 5734    fFrameMenu->Connect(
"Activated(Int_t)", 
"TGuiBldDragManager", 
this, 
"HandleAction(Int_t)");
 
 5736    fPimpl->fLastPopupAction = kNoneAct;
 
 5737    fPimpl->fPlacePopup = kTRUE;
 
 5739    fFrameMenu->PlaceMenu(x, y, kTRUE, kTRUE);
 
 5745 void TGuiBldDragManager::Menu4Lasso(Int_t x, Int_t y)
 
 5747    if (fStop || !fLassoDrawn) {
 
 5755    fLassoMenu = TRootGuiBuilder::CreatePopup();
 
 5756    fLassoMenu->AddLabel(
"Edit actions");
 
 5757    fLassoMenu->AddSeparator();
 
 5758    fLassoMenu->AddEntry(
"Grab\tReturn", kGrabAct);
 
 5759    fLassoMenu->AddSeparator();
 
 5760    fLassoMenu->AddEntry(
"Delete\tDelete", kDeleteAct,
 
 5761                         0, fClient->GetPicture(
"bld_delete.png"));
 
 5762    fLassoMenu->AddEntry(
"Crop\tShift+Delete", kCropAct,
 
 5763                         0, fClient->GetPicture(
"bld_crop.png"));
 
 5764    fLassoMenu->AddSeparator();
 
 5765    fLassoMenu->AddEntry(
"Align Left\tLeft Key", kLeftAct,
 
 5766                         0, fClient->GetPicture(
"bld_AlignLeft.png"));
 
 5767    fLassoMenu->AddEntry(
"Align Right\tRight Key", kRightAct,
 
 5768                         0, fClient->GetPicture(
"bld_AlignRight.png"));
 
 5769    fLassoMenu->AddEntry(
"Align Up\tUp Key", kUpAct,
 
 5770                         0, fClient->GetPicture(
"bld_AlignTop.png"));
 
 5771    fLassoMenu->AddEntry(
"Align Down\tDown Key", kDownAct,
 
 5772                         0, fClient->GetPicture(
"bld_AlignBtm.png"));
 
 5774    fLassoMenu->Connect(
"Activated(Int_t)", 
"TGuiBldDragManager", 
this, 
"HandleAction(Int_t)");
 
 5776    fPimpl->fLastPopupAction = kNoneAct;
 
 5777    fPimpl->fPlacePopup = kTRUE;
 
 5778    fLassoMenu->PlaceMenu(x, y, kTRUE, kTRUE);
 
 5784 Bool_t TGuiBldDragManager::IsPasteFrameExist()
 
 5786    return !gSystem->AccessPathName(fPasteFileName.Data());
 
 5793 TGColorDialog *TGuiBldDragManager::GetGlobalColorDialog(Bool_t create)
 
 5796    static Pixel_t color;
 
 5798    if (!fgGlobalColorDialog && create) {
 
 5799       fgGlobalColorDialog = 
new TGColorDialog(gClient->GetDefaultRoot(), 0,
 
 5800                                               &retc, &color, kFALSE);
 
 5802       for (i = 0; i < 10; i++) {
 
 5803          fgGlobalColorDialog->GetCustomPalette()->SetColor(i, TColor::Number2Pixel(i));
 
 5805       for (i = 0; i < 10; i++) {
 
 5806          fgGlobalColorDialog->GetCustomPalette()->SetColor(10+i, TColor::Number2Pixel(180+i));
 
 5809    return fgGlobalColorDialog;
 
 5815 TGFontDialog *TGuiBldDragManager::GetGlobalFontDialog()
 
 5817    static TGFontDialog::FontProp_t prop;
 
 5819    if (!fgGlobalFontDialog) {
 
 5820      fgGlobalFontDialog = 
new TGFontDialog(gClient->GetDefaultRoot(), 0, &prop, 
"", 0, kFALSE);
 
 5822    return fgGlobalFontDialog;
 
 5828 void TGuiBldDragManager::MapGlobalDialog(TGMainFrame *dialog, TGFrame *fr)
 
 5832    UInt_t dw = gClient->GetDisplayWidth() - 20;
 
 5833    UInt_t dh = gClient->GetDisplayHeight() - 50;
 
 5835    TGFrame *parent = (TGFrame*)fr->GetParent();
 
 5836    gVirtualX->TranslateCoordinates(parent->GetId(), gClient->GetDefaultRoot()->GetId(),
 
 5837                                    fr->GetX() + fr->GetWidth(),
 
 5838                                    fr->GetY() + fr->GetHeight(), x, y, wdummy);
 
 5840    if (x + dialog->GetWidth() > dw) {
 
 5841       x = dw - dialog->GetWidth();
 
 5844    if (y + dialog->GetHeight() > dh) {
 
 5845       y = dh - dialog->GetHeight();
 
 5849    dialog->SetWMPosition(x, y);
 
 5850    dialog->MapRaised();
 
 5856 void TGuiBldDragManager::ChangeBackgroundColor(TGFrame *fr)
 
 5858    TGColorDialog *cd = GetGlobalColorDialog();
 
 5859    cd->SetCurrentColor(fr->GetBackground());
 
 5860    cd->Connect(
"ColorSelected(Pixel_t)", 
"TGFrame", fr, 
"ChangeBackground(Pixel_t)");
 
 5861    MapGlobalDialog(cd, fr);
 
 5862    fClient->WaitForUnmap(cd);
 
 5863    TQObject::Disconnect(cd);
 
 5870 void TGuiBldDragManager::ChangeBackgroundColor(TGCompositeFrame *fr)
 
 5872    TGColorDialog *cd = GetGlobalColorDialog();
 
 5873    cd->SetCurrentColor(fr->GetBackground());
 
 5874    cd->Connect(
"ColorSelected(Pixel_t)", 
"TGCompositeFrame", fr,
 
 5875                "ChangeSubframesBackground(Pixel_t)");
 
 5876    MapGlobalDialog(cd, fr);
 
 5877    fClient->WaitForUnmap(cd);
 
 5878    TQObject::Disconnect(cd);
 
 5885 void TGuiBldDragManager::ChangeTextColor(TGGroupFrame *fr)
 
 5887    TGGC *gc = fClient->GetResourcePool()->GetGCPool()->FindGC(fr->GetNormGC());
 
 5892    ULong_t color = gc->GetForeground();
 
 5894    TGColorDialog *cd = GetGlobalColorDialog();
 
 5895    cd->SetCurrentColor(color);
 
 5896    cd->Connect(
"ColorSelected(Pixel_t)", 
"TGGroupFrame", fr, 
"SetTextColor(Pixel_t)");
 
 5897    MapGlobalDialog(cd, fr);
 
 5898    fClient->WaitForUnmap(cd);
 
 5899    TQObject::Disconnect(cd);
 
 5906 void TGuiBldDragManager::ChangeTextFont(TGGroupFrame *fr)
 
 5908    TGFontDialog *fd = GetGlobalFontDialog();
 
 5910    TGGC *gc = fClient->GetResourcePool()->GetGCPool()->FindGC(fr->GetNormGC());
 
 5916    TGFont *font = fClient->GetResourcePool()->GetFontPool()->FindFont(fr->GetFontStruct());
 
 5921    fd->SetColor(gc->GetForeground());
 
 5923    fd->EnableAlign(kFALSE);
 
 5924    fd->Connect(
"FontSelected(char*)", 
"TGGroupFrame", fr, 
"SetTextFont(char*)");
 
 5925    fd->Connect(
"ColorSelected(Pixel_t)", 
"TGGroupFrame", fr, 
"SetTextColor(Pixel_t)");
 
 5927    MapGlobalDialog(fd, fr);
 
 5928    fClient->WaitForUnmap(fd);
 
 5929    TQObject::Disconnect(fd);
 
 5936 void TGuiBldDragManager::ChangeProperties(TGTextButton *fr)
 
 5938    TGFontDialog *fd = GetGlobalFontDialog();
 
 5940    TGGC *gc = fClient->GetResourcePool()->GetGCPool()->FindGC(fr->GetNormGC());
 
 5945    TGFont *font = fClient->GetResourcePool()->GetFontPool()->FindFont(fr->GetFontStruct());
 
 5950    fd->SetColor(gc->GetForeground());
 
 5952    fd->SetAlign(fr->GetTextJustify());
 
 5954    fd->Connect(
"FontSelected(char*)", 
"TGTextButton", fr, 
"SetFont(char*)");
 
 5955    fd->Connect(
"ColorSelected(Pixel_t)", 
"TGTextButton", fr, 
"SetTextColor(Pixel_t)");
 
 5956    fd->Connect(
"AlignSelected(Int_t)", 
"TGTextButton", fr, 
"SetTextJustify(Int_t)");
 
 5958    MapGlobalDialog(fd, fr);
 
 5959    fClient->WaitForUnmap(fd);
 
 5960    TQObject::Disconnect(fd);
 
 5967 void TGuiBldDragManager::ChangeTextColor(TGTextButton *fr)
 
 5969    TGGC *gc = gClient->GetResourcePool()->GetGCPool()->FindGC(fr->GetNormGC());
 
 5974    ULong_t color = gc->GetForeground();
 
 5976    TGColorDialog *cd = GetGlobalColorDialog();
 
 5977    cd->SetCurrentColor(color);
 
 5978    cd->Connect(
"ColorSelected(Pixel_t)", 
"TGTextButton", fr, 
"SetTextColor(Pixel_t)");
 
 5980    MapGlobalDialog(cd, fr);
 
 5981    fClient->WaitForUnmap(cd);
 
 5982    TQObject::Disconnect(cd);
 
 5989 void TGuiBldDragManager::ChangePicture(TGPictureButton *fr)
 
 5991    static TGFileInfo fi;
 
 5992    static TString dir(
".");
 
 5993    static Bool_t overwr = kFALSE;
 
 5996    fi.fFileTypes = gImageTypes;
 
 5997    fi.fIniDir    = StrDup(dir);
 
 5998    fi.fOverwrite = overwr;
 
 6000    TGWindow *root = (TGWindow*)fClient->GetRoot();
 
 6001    SetEditable(kFALSE);
 
 6003    new TGFileDialog(fClient->GetDefaultRoot(), fr, kFDOpen, &fi);
 
 6005    if (!fi.fFilename) {
 
 6006       root->SetEditable(kTRUE);
 
 6012    overwr = fi.fOverwrite;
 
 6013    fname  = fi.fFilename;
 
 6015    const TGPicture *pic = fClient->GetPicture(fname.Data());
 
 6019       new TGMsgBox(fClient->GetDefaultRoot(), fr, 
"Error...",
 
 6020                    TString::Format(
"Cannot read image file (%s)", fname.Data()),
 
 6021                    kMBIconExclamation, kMBRetry | kMBCancel, &retval);
 
 6023       if (retval == kMBRetry) {
 
 6027       const TGPicture *tmp = fr->GetPicture();
 
 6028       if (tmp) fClient->FreePicture(tmp);
 
 6030       fr->SetPicture(pic);
 
 6033       tmp = fr->GetDisabledPicture();
 
 6034       if (tmp) fClient->FreePicture(tmp);
 
 6036    root->SetEditable(kTRUE);
 
 6043 void TGuiBldDragManager::ChangeBackgroundColor(TGCanvas *fr)
 
 6045    TGColorDialog *cd = GetGlobalColorDialog();
 
 6046    cd->SetCurrentColor(fr->GetBackground());
 
 6047    cd->Connect(
"ColorSelected(Pixel_t)", 
"TGFrame", fr, 
"ChangeBackground(Pixel_t)");
 
 6048    cd->Connect(
"ColorSelected(Pixel_t)", 
"TGScrollBar", fr->GetHScrollbar(), 
"ChangeBackground(Pixel_t)");
 
 6049    cd->Connect(
"ColorSelected(Pixel_t)", 
"TGScrollBar", fr->GetVScrollbar(), 
"ChangeBackground(Pixel_t)");
 
 6051    MapGlobalDialog(cd, fr);
 
 6052    fClient->WaitForUnmap(cd);
 
 6053    TQObject::Disconnect(cd);
 
 6060 void TGuiBldDragManager::ChangeBackgroundColor(TGComboBox *fr)
 
 6062    Pixel_t color = TGFrame::GetWhitePixel();
 
 6064    TGColorDialog *cd = GetGlobalColorDialog();
 
 6065    cd->SetCurrentColor(color);
 
 6067    cd->Connect(
"ColorSelected(Pixel_t)", 
"TGListBox", fr->GetListBox(),
 
 6068                "ChangeBackground(Pixel_t)");
 
 6070    TGLBEntry *se = fr->GetSelectedEntry();
 
 6073       cd->Connect(
"ColorSelected(Pixel_t)", 
"TGLBEntry", se,
 
 6074                   "SetBackgroundColor(Pixel_t)");
 
 6077    TGTextEntry *te = fr->GetTextEntry();
 
 6080       cd->Connect(
"ColorSelected(Pixel_t)", 
"TGTextEntry", te,
 
 6081                   "SetBackgroundColor(Pixel_t)");
 
 6084    MapGlobalDialog(cd, fr);
 
 6085    fClient->WaitForUnmap(cd);
 
 6086    TQObject::Disconnect(cd);
 
 6089       fClient->NeedRedraw(se, kTRUE); 
 
 6093       fClient->NeedRedraw(te, kTRUE);
 
 6101 void TGuiBldDragManager::ChangeProperties(TGLabel *fr)
 
 6103    TGFontDialog *fd = GetGlobalFontDialog();
 
 6105    TGGC *gc = fClient->GetResourcePool()->GetGCPool()->FindGC(fr->GetNormGC());
 
 6111    TGFont *font = fClient->GetResourcePool()->GetFontPool()->FindFont(fr->GetFontStruct());
 
 6117    fd->SetColor(gc->GetForeground());
 
 6119    fd->SetAlign(fr->GetTextJustify());
 
 6121    fd->Connect(
"FontSelected(char*)", 
"TGLabel", fr, 
"SetTextFont(char*)");
 
 6122    fd->Connect(
"ColorSelected(Pixel_t)", 
"TGLabel", fr, 
"SetTextColor(Pixel_t)");
 
 6123    fd->Connect(
"AlignSelected(Int_t)", 
"TGLabel", fr, 
"SetTextJustify(Int_t)");
 
 6125    MapGlobalDialog(fd, fr);
 
 6126    fClient->WaitForUnmap(fd);
 
 6127    TQObject::Disconnect(fd);
 
 6134 void TGuiBldDragManager::ChangeTextColor(TGLabel *fr)
 
 6136    TGGC *gc = gClient->GetResourcePool()->GetGCPool()->FindGC(fr->GetNormGC());
 
 6142    ULong_t color = gc->GetForeground();
 
 6144    TGColorDialog *cd = GetGlobalColorDialog();
 
 6145    cd->SetCurrentColor(color);
 
 6146    cd->Connect(
"ColorSelected(Pixel_t)", 
"TGLabel", fr, 
"SetTextColor(Pixel_t)");
 
 6148    MapGlobalDialog(cd, fr);
 
 6149    fClient->WaitForUnmap(cd);
 
 6150    TQObject::Disconnect(cd);
 
 6157 void TGuiBldDragManager::ChangeBackgroundColor(TGListBox *fr)
 
 6159    Pixel_t color = TGFrame::GetWhitePixel();
 
 6161    TGColorDialog *cd = GetGlobalColorDialog();
 
 6162    cd->SetCurrentColor(color);
 
 6163    cd->Connect(
"ColorSelected(Pixel_t)", 
"TGListBox", fr, 
"ChangeBackground(Pixel_t)");
 
 6165    MapGlobalDialog(cd, fr);
 
 6166    fClient->WaitForUnmap(cd);
 
 6167    TQObject::Disconnect(cd);
 
 6174 void TGuiBldDragManager::ChangeBarColor(TGProgressBar *fr)
 
 6176    ULong_t color = fr->GetBarColor();
 
 6178    TGColorDialog *cd = GetGlobalColorDialog();
 
 6180    cd->SetCurrentColor(color);
 
 6181    cd->Connect(
"ColorSelected(Pixel_t)", 
"TGProgressBar", fr,  
"SetBarColor(Pixel_t)");
 
 6183    MapGlobalDialog(cd, fr);
 
 6184    fClient->WaitForUnmap(cd);
 
 6185    TQObject::Disconnect(cd);
 
 6191 void TGuiBldDragManager::ChangeTextColor(TGProgressBar *fr)
 
 6193    TGGC *gc = gClient->GetResourcePool()->GetGCPool()->FindGC(fr->GetNormGC());
 
 6199    Pixel_t pixel = gc->GetForeground();
 
 6200    TGColorDialog *cd = GetGlobalColorDialog();
 
 6202    cd->SetCurrentColor(pixel);
 
 6203    cd->Connect(
"ColorSelected(Pixel_t)", 
"TGProgressBar", fr,
 
 6204                "SetForegroundColor(Pixel_t)");
 
 6206    MapGlobalDialog(cd, fr);
 
 6207    fClient->WaitForUnmap(cd);
 
 6208    TQObject::Disconnect(cd);
 
 6215 void TGuiBldDragManager::ChangeTextColor(TGTextEntry *fr)
 
 6217    Pixel_t color = fr->GetTextColor();
 
 6219    TGColorDialog *cd = GetGlobalColorDialog();
 
 6220    cd->SetCurrentColor(color);
 
 6221    cd->Connect(
"ColorSelected(Pixel_t)", 
"TGTextEntry", fr, 
"SetTextColor(Pixel_t)");
 
 6223    MapGlobalDialog(cd, fr);
 
 6224    fClient->WaitForUnmap(cd);
 
 6225    TQObject::Disconnect(cd);
 
 6232 void TGuiBldDragManager::ChangeTextFont(TGTextEntry *fr)
 
 6234    TGFontDialog *fd = GetGlobalFontDialog();
 
 6236    fd->SetColor(fr->GetTextColor());
 
 6237    FontStruct_t fs = fr->GetFontStruct();
 
 6238    TGFont *font = fClient->GetResourcePool()->GetFontPool()->FindFont(fs);
 
 6244    fd->EnableAlign(kFALSE);
 
 6245    fd->Connect(
"FontSelected(char*)", 
"TGTextEntry", fr, 
"SetFont(char*)");
 
 6246    fd->Connect(
"ColorSelected(Pixel_t)", 
"TGTextEntry", fr, 
"SetTextColor(Pixel_t)");
 
 6248    MapGlobalDialog(fd, fr);
 
 6249    fClient->WaitForUnmap(fd);
 
 6250    TQObject::Disconnect(fd);
 
 6252    int tw, max_ascent, max_descent;
 
 6253    tw = gVirtualX->TextWidth(fs, fr->GetText(), fr->GetBuffer()->GetTextLength());
 
 6256       TString dummy(
'w', fr->GetBuffer()->GetBufferLength());
 
 6257       tw = gVirtualX->TextWidth(fs, dummy.Data(), dummy.Length());
 
 6260    gVirtualX->GetFontProperties(fs, max_ascent, max_descent);
 
 6261    fr->Resize(tw + 8, max_ascent + max_descent + 7);
 
 6268 void TGuiBldDragManager::ChangeImage(TGIcon *fr)
 
 6270    static TGFileInfo fi;
 
 6271    static TString dir(
".");
 
 6272    static Bool_t overwr = kFALSE;
 
 6275    fi.fFileTypes = gImageTypes;
 
 6276    fi.fIniDir    = StrDup(dir);
 
 6277    fi.fOverwrite = overwr;
 
 6279    TGWindow *root = (TGWindow*)fClient->GetRoot();
 
 6280    SetEditable(kFALSE);
 
 6282    new TGFileDialog(fClient->GetDefaultRoot(), fr, kFDOpen, &fi);
 
 6284    if (!fi.fFilename) {
 
 6285       root->SetEditable(kTRUE);
 
 6286       gDragManager->SetEditable(kTRUE);
 
 6291    overwr = fi.fOverwrite;
 
 6292    fname  = fi.fFilename;
 
 6294    TImage *img = TImage::Open(fname.Data());
 
 6298       new TGMsgBox(fClient->GetDefaultRoot(), fr, 
"Error...",
 
 6299                    TString::Format(
"Cannot read image file (%s)", fname.Data()),
 
 6300                    kMBIconExclamation, kMBRetry | kMBCancel, &retval);
 
 6302       if (retval == kMBRetry) {
 
 6307       fr->SetImagePath(gSystem->DirName(fname.Data()));
 
 6310    root->SetEditable(kTRUE);
 
 6317 void TGuiBldDragManager::SetLassoDrawn(Bool_t on)
 
 6319    if (fLassoDrawn == on) {
 
 6327          fBuilder->EnableEditButtons(kFALSE);
 
 6330       fBuilder->EnableLassoButtons(on);