TGImageMap.h

Go to the documentation of this file.
00001 // @(#)root/gui:$Id: TGImageMap.h 23115 2008-04-10 13:35:37Z rdm $
00002 // Author: Valeriy Onuchin & Fons Rademakers   18/10/2000
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TGImageMap
00013 #define ROOT_TGImageMap
00014 
00015 //////////////////////////////////////////////////////////////////////////
00016 //                                                                      //
00017 // TGImageMap (with TGRegion and TGRegionWithId help classes)           //
00018 //                                                                      //
00019 // A TGImageMap provides the functionality like a clickable image in    //
00020 // a web browser with sensitive regions (MAP HTML tag).                 //
00021 //                                                                      //
00022 //////////////////////////////////////////////////////////////////////////
00023 
00024 #include "TGButton.h"
00025 #include "TPoint.h"
00026 #include "TGDimension.h"
00027 
00028 
00029 class TGRegionData;
00030 class TGPopupMenu;
00031 class TGToolTip;
00032 class TArrayS;
00033 
00034 
00035 class TGRegion : public TObject {
00036 
00037 protected:
00038    TGRegionData   *fData;  // data describing region
00039 
00040    TGRegion(Bool_t);
00041    TGRegion CopyRegion() const;
00042 
00043 public:
00044    enum ERegionType { kRectangle, kEllipse };
00045 
00046    TGRegion();
00047    TGRegion(Int_t x, Int_t y, UInt_t w, UInt_t h, ERegionType = kRectangle);
00048    TGRegion(Int_t n, TPoint *points, Bool_t winding = kFALSE);
00049    TGRegion(Int_t n, Int_t *x, Int_t *y, Bool_t winding = kFALSE);
00050    TGRegion(const TArrayS &x, const TArrayS &y, Bool_t winding = kFALSE);
00051    TGRegion(const TGRegion &reg);
00052    virtual ~TGRegion();
00053 
00054    Bool_t      Contains(const TPoint &p) const;
00055    Bool_t      Contains(Int_t x, Int_t y) const;
00056    TGRegion    Unite(const TGRegion &r) const;
00057    TGRegion    Intersect(const TGRegion &r) const;
00058    TGRegion    Subtract(const TGRegion &r) const;
00059    TGRegion    Eor(const TGRegion &r) const;
00060    TGDimension GetDimension() const;
00061    TGPosition  GetPosition() const;
00062    Bool_t      IsNull() const;
00063    Bool_t      IsEmpty() const;
00064 
00065    TGRegion operator|(const TGRegion &r) const { return Unite(r); }
00066    TGRegion operator+(const TGRegion &r) const { return Unite(r); }
00067    TGRegion operator&(const TGRegion &r) const { return Intersect(r); }
00068    TGRegion operator-(const TGRegion &r) const { return Subtract(r); }
00069    TGRegion operator^(const TGRegion &r) const { return Eor(r); }
00070    TGRegion& operator|=(const TGRegion &r) { return *this = *this | r; }
00071    TGRegion& operator+=(const TGRegion &r) { return *this = *this + r; }
00072    TGRegion& operator&=(const TGRegion &r) { return *this = *this & r; }
00073    TGRegion& operator-=(const TGRegion &r) { return *this = *this - r; }
00074    TGRegion& operator^=(const TGRegion &r) { return *this = *this ^ r; }
00075    Bool_t operator==(const TGRegion &r)  const;
00076    Bool_t operator!=(const TGRegion &r) const { return !(operator==(r)); }
00077    TGRegion &operator=(const TGRegion &r);
00078 
00079    ClassDef(TGRegion,0) // Describes a region
00080 };
00081 
00082 
00083 class TGRegionWithId : public TGRegion {
00084 
00085 private:
00086 
00087    TGRegionWithId& operator=(const TGRegionWithId&); // Not implemented
00088 
00089 protected:
00090    Int_t         fId;      // region id
00091    TGToolTip    *fTip;     // tooltip
00092    TGPopupMenu  *fPopup;   // popup menu
00093 
00094 public:
00095    TGRegionWithId();
00096    TGRegionWithId(Int_t id, Int_t x, Int_t y, UInt_t w, UInt_t h,
00097                   ERegionType = kRectangle);
00098    TGRegionWithId(Int_t id, Int_t n, TPoint *points, Bool_t winding = kFALSE);
00099    TGRegionWithId(const TGRegionWithId &reg);
00100    TGRegionWithId(const TGRegion &reg, Int_t id);
00101    virtual ~TGRegionWithId();
00102 
00103    Int_t        GetId() const { return fId; }
00104    TGToolTip   *GetToolTipText() const { return fTip; }
00105    void         SetToolTipText(const char *text, Long_t delayms,
00106                                const TGFrame *frame);
00107    TGPopupMenu *GetPopup() const { return fPopup; }
00108    void         SetPopup(TGPopupMenu *popup) { fPopup = popup; }
00109    void         DisplayPopup();
00110 
00111    ClassDef(TGRegionWithId,0) // Region with id, tooltip text and popup menu
00112 };
00113 
00114 
00115 class TGImageMap : public TGPictureButton {
00116 
00117 private:
00118   
00119    TGImageMap(const TGImageMap&); // Not implemented
00120    TGImageMap& operator=(const TGImageMap&); // Not implemented
00121 
00122 public:
00123    enum ENavMode { kNavRegions, kNavGrid };
00124 
00125 protected:
00126    TList      *fListOfRegions;   // list of regions
00127    ENavMode    fNavMode;         // navigation mode
00128    ECursor     fCursorMouseOver; // cursor shape in regions
00129    ECursor     fCursorMouseOut;  // cursor shape out of regions
00130    Int_t       fLastVisited;     // id of the last visited region
00131    TGToolTip  *fMainTip;         // tooltip text for main region
00132    TList      *fTrash;           // collect all objects that need to be cleaned up
00133 
00134 public:
00135    TGImageMap(const TGWindow *p = 0, const TGPicture *pic = 0);
00136    TGImageMap(const TGWindow *p, const TString &pic);
00137    virtual ~TGImageMap();
00138 
00139    virtual Bool_t HandleButton(Event_t *event);
00140    virtual Bool_t HandleDoubleClick(Event_t *event);
00141    virtual Bool_t HandleMotion(Event_t *event);
00142 
00143    ENavMode       GetNavMode() { return fNavMode; }
00144    void           AddRegion(const TGRegion &region, Int_t id);
00145    TGPopupMenu   *CreatePopup(Int_t id);
00146    TGPopupMenu   *GetPopup(Int_t id);
00147 
00148    void SetToolTipText(const char *text, Long_t delayms = 300);
00149    void SetToolTipText(Int_t id, const char *text, Long_t delayms = 300);
00150    void SetCursor(ECursor cursor = kHand) { fCursorMouseOver = cursor; }
00151    void SetPicture(const TGPicture * /*new_pic*/) { } // disabled
00152 
00153    virtual void RegionClicked(Int_t id); // *SIGNAL*
00154    virtual void DoubleClicked(Int_t id); // *SIGNAL*
00155    virtual void DoubleClicked();         // *SIGNAL*
00156    virtual void OnMouseOver(Int_t id);   // *SIGNAL*
00157    virtual void OnMouseOut(Int_t id);    // *SIGNAL*
00158 
00159    ClassDef(TGImageMap,0)  // Clickable image (like MAP in HTML)
00160 };
00161 
00162 R__EXTERN TGRegionWithId *gCurrentRegion;
00163 
00164 #endif

Generated on Tue Jul 5 14:20:02 2011 for ROOT_528-00b_version by  doxygen 1.5.1