ROOT logo
// @(#)root/guibuilder:$Id: TGuiBldDragManager.h 20882 2007-11-19 11:31:26Z rdm $
// Author: Valeriy Onuchin   12/09/04

/*************************************************************************
 * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TGuiBldDragManager
#define ROOT_TGuiBldDragManager


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TGuiBldDragManager                                                   //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TGFrame
#include "TGFrame.h"
#endif

#ifndef ROOT_TVirtualDragManager
#include "TVirtualDragManager.h"
#endif

class TTimer;
class TGuiBldDragManagerPimpl;
class TRootGuiBuilder;
class TQUndoManager;
class TGPopupMenu;
class TGuiBldEditor;
class TGColorDialog;
class TGFontDialog;
class TGTextButton;
class TGPictureButton;
class TGCanvas;
class TGComboBox;
class TGLabel;
class TGListBox;
class TGProgressBar;
class TGScrollBar;
class TGTextEntry;
class TGIcon;


enum EActionType { kNoneAct, kPropertyAct, kEditableAct, kReparentAct,
                   kDropAct, kCutAct, kCopyAct, kPasteAct, kCropAct,
                   kCompactAct, kCompactGlobalAct, kLayUpAct, kLayDownAct,
                   kCloneAct, kSaveAct, kSaveFrameAct, kGrabAct, kDeleteAct,
                   kLeftAct, kRightAct, kUpAct, kDownAct, kEndEditAct, kReplaceAct,
                   kGridAct, kBreakLayoutAct, kSwitchLayoutAct, kNewAct,
                   kOpenAct, kLayoutHAct, kLayoutVAct, kUndoAct, kRedoAct, 
                   kSelectAct, kMethodMenuAct, kToggleMenuAct };

class TGuiBldDragManager : public TVirtualDragManager, public TGFrame {

friend class TGClient;
friend class TGFrame;
friend class TGMainFrame;
friend class TGGrabRect;
friend class TRootGuiBuilder;
friend class TGuiBldDragManagerRepeatTimer;

private:
   TGuiBldDragManagerPimpl *fPimpl;    // private data

   TRootGuiBuilder   *fBuilder;        // pointer to gui builder
   TGuiBldEditor *fEditor;             // frame property editor
   Bool_t         fLassoDrawn;         // kTRUE if  lasso drawn
   TString        fPasteFileName;      // paste_clippboard file name
   TString        fTmpBuildFile;       // temporary file name 
   Bool_t         fSelectionIsOn;      // selection with Shift key pressed
   TGPopupMenu   *fFrameMenu;          // context menu for frames
   TGPopupMenu   *fLassoMenu;          // context menu for lasso drawn
   Window_t       fTargetId;           // an id of window where drop 
   Bool_t         fDropStatus;         // kTRUE if drop was successfull
   Bool_t         fStop;               // kTRUE if stopped
   TGFrame       *fSelected;           // selected frame. In most cases selected is 
                                       // the same frame as grabbed frame. 
   TList         *fListOfDialogs;      // list of dialog methods

   static TGColorDialog *fgGlobalColorDialog;   // color dialog
   static TGColorDialog *GetGlobalColorDialog(Bool_t create = kTRUE);

   static TGFontDialog *fgGlobalFontDialog;     // font dialog
   static TGFontDialog *GetGlobalFontDialog();  //
   static void MapGlobalDialog(TGMainFrame *dialog, TGFrame *fr);

   void           Reset1();
   void           DrawGrabRectangles(TGWindow *win = 0);
   void           DrawGrabRect(Int_t i, Int_t x, Int_t y);
   TGCompositeFrame *FindLayoutFrame(TGFrame *f);
   Bool_t         IsPointVisible(Int_t x, Int_t y);
   Bool_t         IsSelectedVisible();
   void           CloseMenus();
   Bool_t         IsEditDisabled(TGWindow *f) const { return (f && (f->GetEditDisabled() & kEditDisable)); }
   Bool_t         IsGrabDisabled(TGWindow *f) const { return (f && (f->GetEditDisabled() & kEditDisableGrab)); }
   Bool_t         IsEventsDisabled(TGWindow *f) const { return (f && (f->GetEditDisabled() & kEditDisableEvents)); }
   Bool_t         IsFixedLayout(TGWindow *f) const { return (f && (f->GetEditDisabled() & kEditDisableLayout)); }
   Bool_t         IsFixedH(TGWindow *f) const { return (f && (f->GetEditDisabled() & kEditDisableHeight)); }
   Bool_t         IsFixedW(TGWindow *f) const { return (f && (f->GetEditDisabled() & kEditDisableWidth)); }
   Bool_t         IsFixedSize(TGWindow *f) const { return (f && (f->GetEditDisabled() & kEditDisableResize)); }
   Bool_t         CanChangeLayout(TGWindow *w) const;
   Bool_t         CanChangeLayoutOrder(TGWindow *w) const;
   Bool_t         CanCompact(TGWindow *w) const;

   void           ChangeSelected(TGFrame *f); 
   TGFrame       *GetEditableParent(TGFrame *f);
   TGFrame       *GetMovableParent(TGWindow *p);
   TGFrame       *GetBtnEnableParent(TGFrame *fr);
   TGWindow      *GetResizableParent(TGWindow *p);
   TGFrame       *FindMdiFrame(TGFrame *in);
   void           RaiseMdiFrame(TGFrame *in);
   Bool_t         CheckTargetAtPoint(Int_t x, Int_t y);
   void           AddClassMenuMethods(TGPopupMenu *menu, TObject *object);
   void           AddDialogMethods(TGPopupMenu *menu, TObject *object);
   void           DeleteMenuDialog();
   void           CreateListOfDialogs();

private:
   TGFrame       *InEditable(Window_t id);
   void           SelectFrame(TGFrame *frame, Bool_t add = kFALSE);
   void           GrabFrame(TGFrame *frame);
   void           UngrabFrame();
   void           SetPropertyEditor(TGuiBldEditor *e);
   void           DeletePropertyEditor();

   TList         *GetFramesInside(Int_t x0, Int_t y0, Int_t x, Int_t y);
   void           ToGrid(Int_t &x, Int_t &y);
   void           DoReplace(TGFrame *frame);
   void           DeleteFrame(TGFrame *frame);
   void           HandleDelete(Bool_t crop = kFALSE);
   void           HandleReturn(Bool_t on = kFALSE);
   void           HandleAlignment(Int_t to, Bool_t lineup = kFALSE);
   void           HandleCut();
   void           HandleCopy(Bool_t brk_layout = kTRUE);
   void           HandlePaste();
   void           HandleReplace();
   void           HandleGrid();
   void           CloneEditable();
   void           DropCanvas(TGCanvas *canvas);
   void           PutToCanvas(TGCompositeFrame *cont);
   Bool_t         Save(const char *file = "");
   Bool_t         SaveFrame(const char *file = 0);
   void           HandleLayoutOrder(Bool_t forward = kTRUE);
   void           DoResize();
   void           DoMove();
   void           DrawLasso();
   void           PlaceFrame(TGFrame*, TGLayoutHints *);
   void           ReparentFrames(TGFrame *newfr,
                                 TGCompositeFrame *oldfr);
   TGCompositeFrame *FindCompositeFrame(Window_t id);
   void           SetCursorType(Int_t cur);
   void           CheckTargetUnderGrab();
   void           HighlightCompositeFrame(Window_t);
   void           Compact(Bool_t global = kTRUE);
   Bool_t         StartDrag(TGFrame *src, Int_t x, Int_t y);
   Bool_t         EndDrag();
   Bool_t         Drop();
   Bool_t         Cancel(Bool_t delSrc);
   void           Menu4Frame(TGFrame *, Int_t x, Int_t y);
   void           Menu4Lasso(Int_t x, Int_t y);
   void           CreatePropertyEditor();
   void           DoRedraw();
   void           SwitchEditable(TGFrame *frame);
   void           UnmapAllPopups();
   void           BreakLayout();
   void           SwitchLayout();

   Bool_t         RecognizeGesture(Event_t *, TGFrame *frame = 0);
   Bool_t         HandleButtonPress(Event_t *);
   Bool_t         HandleButtonRelease(Event_t *);
   Bool_t         HandleButton(Event_t *);
   Bool_t         HandleDoubleClick(Event_t*);
   Bool_t         HandleMotion(Event_t *);
   Bool_t         HandleClientMessage(Event_t *);
   Bool_t         HandleDestroyNotify(Event_t *);
   Bool_t         HandleSelection(Event_t *);
   Bool_t         HandleExpose(Event_t *);
   Bool_t         HandleConfigureNotify(Event_t *);
   Bool_t         HandleSelectionRequest(Event_t *);
   void           HandleButon3Pressed(Event_t *, TGFrame *frame = 0);
   Bool_t         HandleEvent(Event_t *);
   Bool_t         HandleTimer(TTimer *);

   Bool_t         IsMoveWaiting() const;
   Bool_t         IsLassoDrawn() const { return fLassoDrawn; }
   void           SetLassoDrawn(Bool_t on);
   void           HideGrabRectangles();
   Bool_t         IgnoreEvent(Event_t *e);
   Bool_t         CheckDragResize(Event_t *event);
   Bool_t         IsPasteFrameExist();

public:
   TGuiBldDragManager();
   virtual        ~TGuiBldDragManager();

   void           HandleAction(Int_t act);
   Bool_t         HandleKey(Event_t *);

   TGFrame       *GetTarget() const { return fTarget; }
   TGFrame       *GetSelected() const;
   void           Snap2Grid();
   void           SetGridStep(UInt_t step);
   UInt_t         GetGridStep();
   void           HandleUpdateSelected(TGFrame *);
   Int_t          GetStrartDragX() const;     
   Int_t          GetStrartDragY() const;
   Int_t          GetEndDragX() const;
   Int_t          GetEndDragY() const;

   Bool_t         GetDropStatus() const { return fDropStatus; }
   void           SetBuilder(TRootGuiBuilder *b) { fBuilder = b; }

   Bool_t         IsStopped() const { return fStop; }
   void           SetEditable(Bool_t on = kTRUE);

   // hadndling dynamic context menus
   void DoClassMenu(Int_t);
   void DoDialogOK();
   void DoDialogApply();
   void DoDialogCancel();

   void ChangeProperties(TGLabel *);         //*MENU* *DIALOG*icon=bld_fontselect.png*
   void ChangeProperties(TGTextButton *);    //*MENU* *DIALOG*icon=bld_fontselect.png*

   void ChangeTextFont(TGGroupFrame *);      //*MENU* *DIALOG*icon=bld_fontselect.png*
   void ChangeTextFont(TGTextEntry *);       //*MENU* *DIALOG*icon=bld_fontselect.png*

   void ChangePicture(TGPictureButton *);    //*MENU* *DIALOG*icon=bld_open.png*
   void ChangeImage(TGIcon *);               //*MENU* *DIALOG*icon=bld_open.png*

   void ChangeBarColor(TGProgressBar *);     //*MENU* *DIALOG*icon=bld_colorselect.png*

   void ChangeTextColor(TGGroupFrame *);     //*MENU* *DIALOG*icon=bld_colorselect.png*
   void ChangeTextColor(TGLabel *);          //*MENU* *DIALOG*icon=bld_colorselect.png*
   void ChangeTextColor(TGTextButton *);     //*MENU* *DIALOG*icon=bld_colorselect.png*
   void ChangeTextColor(TGProgressBar *);    //*MENU* *DIALOG*icon=bld_colorselect.png*
   void ChangeTextColor(TGTextEntry *);      //*MENU* *DIALOG*icon=bld_colorselect.png*

   void ChangeBackgroundColor(TGListBox *);  //*MENU* *DIALOG*icon=bld_colorselect.png*
   void ChangeBackgroundColor(TGCanvas *);   //*MENU* *DIALOG*icon=bld_colorselect.png*
   void ChangeBackgroundColor(TGComboBox *); //*MENU* *DIALOG*icon=bld_colorselect.png*
   void ChangeBackgroundColor(TGFrame *);             //*MENU* *DIALOG*icon=bld_colorselect.png*
   void ChangeBackgroundColor(TGCompositeFrame *);    //*MENU* *DIALOG*icon=bld_colorselect.png*

   ClassDef(TGuiBldDragManager,0)  // drag and drop manager
};


#endif
 TGuiBldDragManager.h:1
 TGuiBldDragManager.h:2
 TGuiBldDragManager.h:3
 TGuiBldDragManager.h:4
 TGuiBldDragManager.h:5
 TGuiBldDragManager.h:6
 TGuiBldDragManager.h:7
 TGuiBldDragManager.h:8
 TGuiBldDragManager.h:9
 TGuiBldDragManager.h:10
 TGuiBldDragManager.h:11
 TGuiBldDragManager.h:12
 TGuiBldDragManager.h:13
 TGuiBldDragManager.h:14
 TGuiBldDragManager.h:15
 TGuiBldDragManager.h:16
 TGuiBldDragManager.h:17
 TGuiBldDragManager.h:18
 TGuiBldDragManager.h:19
 TGuiBldDragManager.h:20
 TGuiBldDragManager.h:21
 TGuiBldDragManager.h:22
 TGuiBldDragManager.h:23
 TGuiBldDragManager.h:24
 TGuiBldDragManager.h:25
 TGuiBldDragManager.h:26
 TGuiBldDragManager.h:27
 TGuiBldDragManager.h:28
 TGuiBldDragManager.h:29
 TGuiBldDragManager.h:30
 TGuiBldDragManager.h:31
 TGuiBldDragManager.h:32
 TGuiBldDragManager.h:33
 TGuiBldDragManager.h:34
 TGuiBldDragManager.h:35
 TGuiBldDragManager.h:36
 TGuiBldDragManager.h:37
 TGuiBldDragManager.h:38
 TGuiBldDragManager.h:39
 TGuiBldDragManager.h:40
 TGuiBldDragManager.h:41
 TGuiBldDragManager.h:42
 TGuiBldDragManager.h:43
 TGuiBldDragManager.h:44
 TGuiBldDragManager.h:45
 TGuiBldDragManager.h:46
 TGuiBldDragManager.h:47
 TGuiBldDragManager.h:48
 TGuiBldDragManager.h:49
 TGuiBldDragManager.h:50
 TGuiBldDragManager.h:51
 TGuiBldDragManager.h:52
 TGuiBldDragManager.h:53
 TGuiBldDragManager.h:54
 TGuiBldDragManager.h:55
 TGuiBldDragManager.h:56
 TGuiBldDragManager.h:57
 TGuiBldDragManager.h:58
 TGuiBldDragManager.h:59
 TGuiBldDragManager.h:60
 TGuiBldDragManager.h:61
 TGuiBldDragManager.h:62
 TGuiBldDragManager.h:63
 TGuiBldDragManager.h:64
 TGuiBldDragManager.h:65
 TGuiBldDragManager.h:66
 TGuiBldDragManager.h:67
 TGuiBldDragManager.h:68
 TGuiBldDragManager.h:69
 TGuiBldDragManager.h:70
 TGuiBldDragManager.h:71
 TGuiBldDragManager.h:72
 TGuiBldDragManager.h:73
 TGuiBldDragManager.h:74
 TGuiBldDragManager.h:75
 TGuiBldDragManager.h:76
 TGuiBldDragManager.h:77
 TGuiBldDragManager.h:78
 TGuiBldDragManager.h:79
 TGuiBldDragManager.h:80
 TGuiBldDragManager.h:81
 TGuiBldDragManager.h:82
 TGuiBldDragManager.h:83
 TGuiBldDragManager.h:84
 TGuiBldDragManager.h:85
 TGuiBldDragManager.h:86
 TGuiBldDragManager.h:87
 TGuiBldDragManager.h:88
 TGuiBldDragManager.h:89
 TGuiBldDragManager.h:90
 TGuiBldDragManager.h:91
 TGuiBldDragManager.h:92
 TGuiBldDragManager.h:93
 TGuiBldDragManager.h:94
 TGuiBldDragManager.h:95
 TGuiBldDragManager.h:96
 TGuiBldDragManager.h:97
 TGuiBldDragManager.h:98
 TGuiBldDragManager.h:99
 TGuiBldDragManager.h:100
 TGuiBldDragManager.h:101
 TGuiBldDragManager.h:102
 TGuiBldDragManager.h:103
 TGuiBldDragManager.h:104
 TGuiBldDragManager.h:105
 TGuiBldDragManager.h:106
 TGuiBldDragManager.h:107
 TGuiBldDragManager.h:108
 TGuiBldDragManager.h:109
 TGuiBldDragManager.h:110
 TGuiBldDragManager.h:111
 TGuiBldDragManager.h:112
 TGuiBldDragManager.h:113
 TGuiBldDragManager.h:114
 TGuiBldDragManager.h:115
 TGuiBldDragManager.h:116
 TGuiBldDragManager.h:117
 TGuiBldDragManager.h:118
 TGuiBldDragManager.h:119
 TGuiBldDragManager.h:120
 TGuiBldDragManager.h:121
 TGuiBldDragManager.h:122
 TGuiBldDragManager.h:123
 TGuiBldDragManager.h:124
 TGuiBldDragManager.h:125
 TGuiBldDragManager.h:126
 TGuiBldDragManager.h:127
 TGuiBldDragManager.h:128
 TGuiBldDragManager.h:129
 TGuiBldDragManager.h:130
 TGuiBldDragManager.h:131
 TGuiBldDragManager.h:132
 TGuiBldDragManager.h:133
 TGuiBldDragManager.h:134
 TGuiBldDragManager.h:135
 TGuiBldDragManager.h:136
 TGuiBldDragManager.h:137
 TGuiBldDragManager.h:138
 TGuiBldDragManager.h:139
 TGuiBldDragManager.h:140
 TGuiBldDragManager.h:141
 TGuiBldDragManager.h:142
 TGuiBldDragManager.h:143
 TGuiBldDragManager.h:144
 TGuiBldDragManager.h:145
 TGuiBldDragManager.h:146
 TGuiBldDragManager.h:147
 TGuiBldDragManager.h:148
 TGuiBldDragManager.h:149
 TGuiBldDragManager.h:150
 TGuiBldDragManager.h:151
 TGuiBldDragManager.h:152
 TGuiBldDragManager.h:153
 TGuiBldDragManager.h:154
 TGuiBldDragManager.h:155
 TGuiBldDragManager.h:156
 TGuiBldDragManager.h:157
 TGuiBldDragManager.h:158
 TGuiBldDragManager.h:159
 TGuiBldDragManager.h:160
 TGuiBldDragManager.h:161
 TGuiBldDragManager.h:162
 TGuiBldDragManager.h:163
 TGuiBldDragManager.h:164
 TGuiBldDragManager.h:165
 TGuiBldDragManager.h:166
 TGuiBldDragManager.h:167
 TGuiBldDragManager.h:168
 TGuiBldDragManager.h:169
 TGuiBldDragManager.h:170
 TGuiBldDragManager.h:171
 TGuiBldDragManager.h:172
 TGuiBldDragManager.h:173
 TGuiBldDragManager.h:174
 TGuiBldDragManager.h:175
 TGuiBldDragManager.h:176
 TGuiBldDragManager.h:177
 TGuiBldDragManager.h:178
 TGuiBldDragManager.h:179
 TGuiBldDragManager.h:180
 TGuiBldDragManager.h:181
 TGuiBldDragManager.h:182
 TGuiBldDragManager.h:183
 TGuiBldDragManager.h:184
 TGuiBldDragManager.h:185
 TGuiBldDragManager.h:186
 TGuiBldDragManager.h:187
 TGuiBldDragManager.h:188
 TGuiBldDragManager.h:189
 TGuiBldDragManager.h:190
 TGuiBldDragManager.h:191
 TGuiBldDragManager.h:192
 TGuiBldDragManager.h:193
 TGuiBldDragManager.h:194
 TGuiBldDragManager.h:195
 TGuiBldDragManager.h:196
 TGuiBldDragManager.h:197
 TGuiBldDragManager.h:198
 TGuiBldDragManager.h:199
 TGuiBldDragManager.h:200
 TGuiBldDragManager.h:201
 TGuiBldDragManager.h:202
 TGuiBldDragManager.h:203
 TGuiBldDragManager.h:204
 TGuiBldDragManager.h:205
 TGuiBldDragManager.h:206
 TGuiBldDragManager.h:207
 TGuiBldDragManager.h:208
 TGuiBldDragManager.h:209
 TGuiBldDragManager.h:210
 TGuiBldDragManager.h:211
 TGuiBldDragManager.h:212
 TGuiBldDragManager.h:213
 TGuiBldDragManager.h:214
 TGuiBldDragManager.h:215
 TGuiBldDragManager.h:216
 TGuiBldDragManager.h:217
 TGuiBldDragManager.h:218
 TGuiBldDragManager.h:219
 TGuiBldDragManager.h:220
 TGuiBldDragManager.h:221
 TGuiBldDragManager.h:222
 TGuiBldDragManager.h:223
 TGuiBldDragManager.h:224
 TGuiBldDragManager.h:225
 TGuiBldDragManager.h:226
 TGuiBldDragManager.h:227
 TGuiBldDragManager.h:228
 TGuiBldDragManager.h:229
 TGuiBldDragManager.h:230
 TGuiBldDragManager.h:231
 TGuiBldDragManager.h:232
 TGuiBldDragManager.h:233
 TGuiBldDragManager.h:234
 TGuiBldDragManager.h:235
 TGuiBldDragManager.h:236
 TGuiBldDragManager.h:237
 TGuiBldDragManager.h:238
 TGuiBldDragManager.h:239
 TGuiBldDragManager.h:240
 TGuiBldDragManager.h:241
 TGuiBldDragManager.h:242
 TGuiBldDragManager.h:243
 TGuiBldDragManager.h:244
 TGuiBldDragManager.h:245
 TGuiBldDragManager.h:246
 TGuiBldDragManager.h:247
 TGuiBldDragManager.h:248
 TGuiBldDragManager.h:249
 TGuiBldDragManager.h:250
 TGuiBldDragManager.h:251
 TGuiBldDragManager.h:252
 TGuiBldDragManager.h:253
 TGuiBldDragManager.h:254
 TGuiBldDragManager.h:255