ROOT logo
// @(#)root/gui:$Id$
// Author: Bertrand Bellenot + Fons Rademakers   22/08/02

/*************************************************************************
 * Copyright (C) 1995-2002, 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_TGColorSelect
#define ROOT_TGColorSelect

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TGColorFrame, TG16ColorSelector, TGColorPopup and TGColorSelect.     //
//                                                                      //
// The TGColorFrame is a small frame with border showing a specific     //
// color.                                                               //
//                                                                      //
// The TG16ColorSelector is a composite frame with 16 TGColorFrames.    //
//                                                                      //
// The TGColorPopup is a popup containing a TG16ColorSelector and a     //
// "More..." button which popups up a TGColorDialog allowing custom     //
// color selection.                                                     //
//                                                                      //
// The TGColorSelect widget is like a checkbutton but instead of the    //
// check mark there is color area with a little down arrow. When        //
// clicked on the arrow the TGColorPopup pops up.                       //
//                                                                      //
// Selecting a color in this widget will generate the event:            //
// kC_COLORSEL, kCOL_SELCHANGED, widget id, pixel.                      //
// and the signal:                                                      //
// ColorSelected(Pixel_t pixel)                                         //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

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


//----------------------------------------------------------------------

class TGColorFrame : public TGFrame {

protected:
   const TGWindow *fMsgWindow;   // window handling container messages
   Pixel_t         fPixel;       // color value of this cell
   Bool_t          fActive;      // kTRUE if this color cell is active
   GContext_t      fGrayGC;      // Shadow GC
   Pixel_t         fColor;       // returned color value

private:
   TGColorFrame(const TGColorFrame&);             // not implemented
   TGColorFrame& operator=(const TGColorFrame&);  // not implemented

public:
   TGColorFrame(const TGWindow *p = 0, Pixel_t c = 0, Int_t n = 1);
   virtual ~TGColorFrame() { }

   virtual Bool_t  HandleButton(Event_t *event);
   virtual void    DrawBorder();

   void     SetActive(Bool_t in) { fActive = in; gClient->NeedRedraw(this); }
   Pixel_t  GetColor() const { return fColor; }

   ClassDef(TGColorFrame,0)  // Frame for color cell
};

//----------------------------------------------------------------------

class TG16ColorSelector : public TGCompositeFrame {

protected:
   Int_t            fActive;     // index of active color cell
   const TGWindow  *fMsgWindow;  // window handling container messages
   TGColorFrame    *fCe[16];     // matrix of color cells

private:
   TG16ColorSelector(const TG16ColorSelector&);             // not implemented
   TG16ColorSelector& operator=(const TG16ColorSelector&);  // not implemented

public:
   TG16ColorSelector(const TGWindow *p = 0);
   virtual ~TG16ColorSelector();

   virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);

   void    SetActive(Int_t newat);
   Int_t   GetActive() { return fActive; }

   ClassDef(TG16ColorSelector,0)  // 16 color cells
};

//----------------------------------------------------------------------

class TGColorPopup : public TGCompositeFrame {

protected:
   Int_t            fActive;        // active color index
   Int_t            fLaunchDialog;  // flag used for launching color dialog
   const TGWindow  *fMsgWindow;     // window handling container messages
   Pixel_t          fCurrentColor;  // currently selected color value

private:
   TGColorPopup(const TGColorPopup&);              // not implemented
   TGColorPopup& operator=(const TGColorPopup&);   // not implemented

public:
   TGColorPopup(const TGWindow *p = 0, const TGWindow *m = 0, Pixel_t color = 0);
   virtual ~TGColorPopup();

   virtual Bool_t HandleButton(Event_t *event);
   virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);

   void    PlacePopup(Int_t x, Int_t y, UInt_t w, UInt_t h);
   void    EndPopup();
   void    PreviewColor(Pixel_t color);
   void    PreviewAlphaColor(ULong_t color);

   ClassDef(TGColorPopup,0)  // Color selector popup
};

//----------------------------------------------------------------------

class TGColorSelect : public TGCheckButton {

protected:
   Pixel_t       fColor;         // color value of the button
   TGGC          fDrawGC;        // drawing GC
   TGColorPopup *fColorPopup;    // color popup associated
   TGPosition    fPressPos;      // psotion of frame on button press event

   virtual void DoRedraw();

   void DrawTriangle(GContext_t gc, Int_t x, Int_t y);

private:
   TGColorSelect(const TGColorSelect&);             // not implemented
   TGColorSelect& operator=(const TGColorSelect&);  // not implemented

public:
   TGColorSelect(const TGWindow *p = 0, Pixel_t color = 0,
                 Int_t id = -1);
   virtual ~TGColorSelect();

   virtual Bool_t HandleButton(Event_t *event);
   virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);

   void    SetColor(Pixel_t color, Bool_t emit = kTRUE);
   void    SetAlphaColor(ULong_t color, Bool_t emit = kTRUE);
   Pixel_t GetColor() const { return fColor; }
   void    Enable(Bool_t on = kTRUE);  //*TOGGLE* *GETTER=IsEnabled
   void    Disable();

   // dummy methods just to remove from context menu
   void SetDown(Bool_t on = kTRUE, Bool_t emit = kFALSE) { TGButton::SetDown(on, emit); }
   void Rename(const char *title)  { TGTextButton::SetTitle(title); }
   void SetEnabled(Bool_t e = kTRUE) {TGButton::SetEnabled(e); }

   virtual TGDimension GetDefaultSize() const { return TGDimension(43, 21); }
   virtual void SavePrimitive(std::ostream &out, Option_t * = "");

   virtual void ColorSelected(Pixel_t color = 0)
            { Emit("ColorSelected(Pixel_t)", color ? color : GetColor()); }  //*SIGNAL*
   virtual void AlphaColorSelected(ULong_t colptr = 0)
            { Emit("AlphaColorSelected(ULong_t)", colptr); }  //*SIGNAL*

   ClassDef(TGColorSelect,0)  // Color selection checkbutton
};

#endif
 TGColorSelect.h:1
 TGColorSelect.h:2
 TGColorSelect.h:3
 TGColorSelect.h:4
 TGColorSelect.h:5
 TGColorSelect.h:6
 TGColorSelect.h:7
 TGColorSelect.h:8
 TGColorSelect.h:9
 TGColorSelect.h:10
 TGColorSelect.h:11
 TGColorSelect.h:12
 TGColorSelect.h:13
 TGColorSelect.h:14
 TGColorSelect.h:15
 TGColorSelect.h:16
 TGColorSelect.h:17
 TGColorSelect.h:18
 TGColorSelect.h:19
 TGColorSelect.h:20
 TGColorSelect.h:21
 TGColorSelect.h:22
 TGColorSelect.h:23
 TGColorSelect.h:24
 TGColorSelect.h:25
 TGColorSelect.h:26
 TGColorSelect.h:27
 TGColorSelect.h:28
 TGColorSelect.h:29
 TGColorSelect.h:30
 TGColorSelect.h:31
 TGColorSelect.h:32
 TGColorSelect.h:33
 TGColorSelect.h:34
 TGColorSelect.h:35
 TGColorSelect.h:36
 TGColorSelect.h:37
 TGColorSelect.h:38
 TGColorSelect.h:39
 TGColorSelect.h:40
 TGColorSelect.h:41
 TGColorSelect.h:42
 TGColorSelect.h:43
 TGColorSelect.h:44
 TGColorSelect.h:45
 TGColorSelect.h:46
 TGColorSelect.h:47
 TGColorSelect.h:48
 TGColorSelect.h:49
 TGColorSelect.h:50
 TGColorSelect.h:51
 TGColorSelect.h:52
 TGColorSelect.h:53
 TGColorSelect.h:54
 TGColorSelect.h:55
 TGColorSelect.h:56
 TGColorSelect.h:57
 TGColorSelect.h:58
 TGColorSelect.h:59
 TGColorSelect.h:60
 TGColorSelect.h:61
 TGColorSelect.h:62
 TGColorSelect.h:63
 TGColorSelect.h:64
 TGColorSelect.h:65
 TGColorSelect.h:66
 TGColorSelect.h:67
 TGColorSelect.h:68
 TGColorSelect.h:69
 TGColorSelect.h:70
 TGColorSelect.h:71
 TGColorSelect.h:72
 TGColorSelect.h:73
 TGColorSelect.h:74
 TGColorSelect.h:75
 TGColorSelect.h:76
 TGColorSelect.h:77
 TGColorSelect.h:78
 TGColorSelect.h:79
 TGColorSelect.h:80
 TGColorSelect.h:81
 TGColorSelect.h:82
 TGColorSelect.h:83
 TGColorSelect.h:84
 TGColorSelect.h:85
 TGColorSelect.h:86
 TGColorSelect.h:87
 TGColorSelect.h:88
 TGColorSelect.h:89
 TGColorSelect.h:90
 TGColorSelect.h:91
 TGColorSelect.h:92
 TGColorSelect.h:93
 TGColorSelect.h:94
 TGColorSelect.h:95
 TGColorSelect.h:96
 TGColorSelect.h:97
 TGColorSelect.h:98
 TGColorSelect.h:99
 TGColorSelect.h:100
 TGColorSelect.h:101
 TGColorSelect.h:102
 TGColorSelect.h:103
 TGColorSelect.h:104
 TGColorSelect.h:105
 TGColorSelect.h:106
 TGColorSelect.h:107
 TGColorSelect.h:108
 TGColorSelect.h:109
 TGColorSelect.h:110
 TGColorSelect.h:111
 TGColorSelect.h:112
 TGColorSelect.h:113
 TGColorSelect.h:114
 TGColorSelect.h:115
 TGColorSelect.h:116
 TGColorSelect.h:117
 TGColorSelect.h:118
 TGColorSelect.h:119
 TGColorSelect.h:120
 TGColorSelect.h:121
 TGColorSelect.h:122
 TGColorSelect.h:123
 TGColorSelect.h:124
 TGColorSelect.h:125
 TGColorSelect.h:126
 TGColorSelect.h:127
 TGColorSelect.h:128
 TGColorSelect.h:129
 TGColorSelect.h:130
 TGColorSelect.h:131
 TGColorSelect.h:132
 TGColorSelect.h:133
 TGColorSelect.h:134
 TGColorSelect.h:135
 TGColorSelect.h:136
 TGColorSelect.h:137
 TGColorSelect.h:138
 TGColorSelect.h:139
 TGColorSelect.h:140
 TGColorSelect.h:141
 TGColorSelect.h:142
 TGColorSelect.h:143
 TGColorSelect.h:144
 TGColorSelect.h:145
 TGColorSelect.h:146
 TGColorSelect.h:147
 TGColorSelect.h:148
 TGColorSelect.h:149
 TGColorSelect.h:150
 TGColorSelect.h:151
 TGColorSelect.h:152
 TGColorSelect.h:153
 TGColorSelect.h:154
 TGColorSelect.h:155
 TGColorSelect.h:156
 TGColorSelect.h:157
 TGColorSelect.h:158
 TGColorSelect.h:159
 TGColorSelect.h:160
 TGColorSelect.h:161
 TGColorSelect.h:162
 TGColorSelect.h:163
 TGColorSelect.h:164
 TGColorSelect.h:165
 TGColorSelect.h:166
 TGColorSelect.h:167
 TGColorSelect.h:168
 TGColorSelect.h:169
 TGColorSelect.h:170
 TGColorSelect.h:171
 TGColorSelect.h:172
 TGColorSelect.h:173
 TGColorSelect.h:174
 TGColorSelect.h:175
 TGColorSelect.h:176
 TGColorSelect.h:177