Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TContextMenu.h
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Nenad Buncic 08/02/96
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TContextMenu
13 #define ROOT_TContextMenu
14 
15 
16 ////////////////////////////////////////////////////////////////////////////////
17 // //
18 // TContextMenu //
19 // //
20 // This class provides an interface to context sensitive popup menus. //
21 // These menus pop up when the user hits the right mouse button, and //
22 // are destroyed when the menu pops downs. //
23 // //
24 ////////////////////////////////////////////////////////////////////////////////
25 
26 #include "TContextMenuImp.h"
27 
28 #include "TNamed.h"
29 
30 class TMethod;
31 class TFunction;
32 class TMethodArg;
33 class TVirtualPad;
34 class TObjArray;
35 class TBrowser;
36 class TToggle;
37 class TClassMenuItem;
38 
39 
40 class TContextMenu : public TNamed {
41 
42 friend class TContextMenuImp;
43 
44 private:
45  TContextMenu(const TContextMenu&) = delete; // TContextMenu can not be copied since we do not know the actual type of the TContextMenuImp (and it can not be 'Cloned')
46  TContextMenu& operator=(const TContextMenu&) = delete; // TContextMenu can not be copied since we do not know the actual type of the TContextMenuImp (and it can not be 'Cloned')
47 
48 protected:
49  TContextMenuImp *fContextMenuImp; //!Context menu system specific implementation
50  TFunction *fSelectedMethod; //selected method
51  TObject *fSelectedObject; //selected object
52  TObject *fCalledObject; //object to call
53  TClassMenuItem *fSelectedMenuItem; //selected class menu item
54  TVirtualPad *fSelectedCanvas; //selected canvas (if exist)
55  TVirtualPad *fSelectedPad; //selected pad (if exist)
56  TBrowser *fBrowser; //selected browser (if exist)
57 
58  virtual void DisplayPopUp(Int_t x, Int_t y)
59  { if (fContextMenuImp) fContextMenuImp->DisplayPopup(x, y); }
60 
61 private:
62  TContextMenu();
63 
64 public:
65  TContextMenu(const char *name, const char *title = "Context sensitive popup menu");
66  virtual ~TContextMenu();
67 
68  virtual void Action(TObject *object, TMethod *method);
69  virtual void Action(TObject *object, TToggle *toggle);
70  virtual void Action(TClassMenuItem *classmenuitem);
71  void Action(TMethod *method) { Action(fSelectedObject, method); }
72  void Action(TToggle *toggle) { Action(fSelectedObject, toggle); }
73  virtual const char *CreateArgumentTitle(TMethodArg *argument);
74  virtual const char *CreateDialogTitle(TObject *object, TFunction *method);
75  virtual const char *CreatePopupTitle(TObject *object );
76  virtual void Execute(const char *method, const char *params, Int_t *error=nullptr) { TObject::Execute(method, params, error); }
77  virtual void Execute(TMethod *method, TObjArray *params, Int_t *error=nullptr) { TObject::Execute(method, params, error); }
78  virtual void Execute(TObject *object, TFunction *method, const char *params);
79  virtual void Execute(TObject *object, TFunction *method, TObjArray *params);
80  void Execute(const char *params) { Execute(fCalledObject, fSelectedMethod, params); }
81  void Execute(TObjArray *params) { Execute(fCalledObject, fSelectedMethod, params); }
82  virtual TBrowser *GetBrowser() { return fBrowser; }
83  virtual TContextMenuImp *GetContextMenuImp() { return fContextMenuImp; }
84  virtual TVirtualPad *GetSelectedCanvas() { return fSelectedCanvas; }
85  virtual TFunction *GetSelectedMethod() { return fSelectedMethod; }
86  virtual TObject *GetSelectedObject() { return fSelectedObject; }
87  virtual TObject *GetCalledObject() { return fCalledObject; }
88  virtual TClassMenuItem *GetSelectedMenuItem() { return fSelectedMenuItem; }
89  virtual TVirtualPad *GetSelectedPad() { return fSelectedPad; }
90  virtual void Popup(Int_t x, Int_t y, TObject *obj, TVirtualPad *c=nullptr, TVirtualPad *p=nullptr); // Create menu from canvas
91  virtual void Popup(Int_t x, Int_t y, TObject *obj, TBrowser *b); // Create menu from Browser
92  virtual void SetCanvas(TVirtualPad *c) { fSelectedCanvas = c; }
93  virtual void SetBrowser(TBrowser *b) { fBrowser = b; }
94  virtual void SetMethod(TFunction *m) { fSelectedMethod = m; }
95  virtual void SetCalledObject(TObject *o) { fCalledObject = o; }
96  virtual void SetSelectedMenuItem(TClassMenuItem *mi) { fSelectedMenuItem = mi; }
97  virtual void SetNameTitle(const char *name, const char *title) { TNamed::SetNameTitle(name, title); }
98  virtual void SetObject(TObject *o) { fSelectedObject = o; }
99  virtual void SetPad(TVirtualPad *p) { fSelectedPad = p; }
100 
101  ClassDef(TContextMenu,0) //Context sensitive popup menu
102 };
103 
104 #endif