ROOT  6.06/09
Reference Guide
TGedMarkerSelect.cxx
Go to the documentation of this file.
1 // @(#)root/ged:$Id$
2 // Author: Marek Biskup, Ilka Antcheva 22/07/03
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2002, 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 
13 //////////////////////////////////////////////////////////////////////////
14 // //
15 // TGedMarkerSelect, TGedMarkerPopup //
16 // //
17 // The TGedMarkerPopup is a popup containing buttons to //
18 // select marker style. //
19 // //
20 // The TGedMarkerSelect widget is a button showing selected marker //
21 // and a little down arrow. When clicked on the arrow the //
22 // TGedMarkerPopup pops up. //
23 // //
24 // Selecting a marker in this widget will generate the event: //
25 // kC_MARKERSEL, kMAR_SELCHANGED, widget id, style. //
26 // //
27 // and the signal: //
28 // MarkerSelected(Style_t marker) //
29 // //
30 //////////////////////////////////////////////////////////////////////////
31 
32 #include "TGedMarkerSelect.h"
33 #include "TGPicture.h"
34 #include "TGToolTip.h"
35 #include "TGButton.h"
36 #include "Riostream.h"
37 
40 
41 struct MarkerDescription_t {
42  const char* fFilename; // xpm file name
43  const char* fName; // type number for tooltip
44  Int_t fNumber; // marker type number
45 };
46 
47 static MarkerDescription_t gMarkers[] = {
48 
49  {"marker1.xpm", "1", 1},
50  {"marker6.xpm", "6", 6},
51  {"marker7.xpm", "7", 7},
52  {"marker2.xpm", "2", 2},
53  {"marker3.xpm", "3", 3},
54  {"marker4.xpm", "4", 4},
55  {"marker5.xpm", "5", 5},
56  {"marker20.xpm", "20", 20},
57  {"marker21.xpm", "21", 21},
58  {"marker22.xpm", "22", 22},
59  {"marker23.xpm", "23", 23},
60  {"marker24.xpm", "24", 24},
61  {"marker25.xpm", "25", 25},
62  {"marker26.xpm", "26", 26},
63  {"marker27.xpm", "27", 27},
64  {"marker28.xpm", "28", 28},
65  {"marker29.xpm", "29", 29},
66  {"marker30.xpm", "30", 30},
67  {0, 0, 0},
68 };
69 
70 static MarkerDescription_t* GetMarkerByNumber(Int_t number)
71 {
72  for (Int_t i = 0; gMarkers[i].fFilename != 0; i++) {
73  if (gMarkers[i].fNumber == number)
74  return &gMarkers[i];
75  }
76  return 0;
77 }
78 
79 ////////////////////////////////////////////////////////////////////////////////
80 /// Create marker popup window.
81 
84  GetDefaultFrameBackground())
85 {
86  TGButton *b;
87  fCurrentStyle = markerStyle;
88 
89  Pixel_t white;
90  gClient->GetColorByName("white", white); // white background
91  SetBackgroundColor(white);
92 
93  SetLayoutManager(new TGTileLayout(this, 1));
94 
95  for (int i = 0; gMarkers[i].fFilename != 0; i++) {
96  AddFrame(b = new TGPictureButton(this, gMarkers[i].fFilename,
98  new TGLayoutHints(kLHintsLeft, 14, 14, 14, 14));
100  }
101 
102  Resize(65, 94);
103  MapSubwindows();
104 }
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 /// Destructor.
108 
110 {
111  TGFrameElement *el;
112  TIter next(GetList());
113  while ((el = (TGFrameElement *)next())) {
115  fClient->FreePicture(((TGPictureButton *)el->fFrame)->GetPicture());
116  }
117  Cleanup();
118 }
119 
120 ////////////////////////////////////////////////////////////////////////////////
121 /// Process messages generated by the marker popup window.
122 
124 {
125  if (GET_MSG(msg) == kC_COMMAND && GET_SUBMSG(msg) == kCM_BUTTON) {
127  EndPopup();
128  }
129 
130  if (parm2) {
131  // no warning
132  }
133 
134  return kTRUE;
135 }
136 
137 ////////////////////////////////////////////////////////////////////////////////
138 /// Create and show marker popup window.
139 
141  : TGedSelect(p, id)
142 {
143  fPicture = 0;
144  SetPopup(new TGedMarkerPopup(gClient->GetDefaultRoot(), this, markerStyle));
145  SetMarkerStyle(markerStyle);
146 
147 }
148 
149 ////////////////////////////////////////////////////////////////////////////////
150 /// Process messages according to the user input.
151 
153 {
154  if (GET_MSG(msg) == kC_MARKERSEL && GET_SUBMSG(msg) == kMAR_SELCHANGED) {
155  SetMarkerStyle(parm2);
156  parm1 = (Long_t)fWidgetId;
158  parm1, parm2);
159  }
160 
161  return kTRUE;
162 }
163 
164 ////////////////////////////////////////////////////////////////////////////////
165 /// Draw selected marker type as current one.
166 
168 {
170 
171  Int_t x, y;
172  UInt_t w, h;
173 
174  if (IsEnabled()) {
175  // pattern rectangle
176 
177  x = fBorderWidth + 2;
178  y = fBorderWidth + 2; // 1;
179  h = fHeight - (fBorderWidth * 2) - 4; // -3; // 14
180  w = h;
181  if (fState == kButtonDown) {
182  ++x; ++y;
183  }
184  gVirtualX->DrawRectangle(fId, GetShadowGC()(), x, y, w - 1, h - 1);
185 
186  if (fPicture != 0) fPicture->Draw(fId, fDrawGC->GetGC(), x + 1, y + 1);
187  } else { // sunken rectangle
188  x = fBorderWidth + 2;
189  y = fBorderWidth + 2; // 1;
190  w = 42;
191  h = fHeight - (fBorderWidth * 2) - 4; // 3;
192  Draw3dRectangle(kSunkenFrame, x, y, w, h);
193  }
194 }
195 
196 ////////////////////////////////////////////////////////////////////////////////
197 /// Set marker.
198 
200 {
201  fMarkerStyle = markerStyle;
202  gClient->NeedRedraw(this);
203 
204  if (fPicture) {
205  gClient->FreePicture(fPicture);
206  fPicture = 0;
207  }
208 
209  MarkerDescription_t *md = GetMarkerByNumber(fMarkerStyle);
210 
211  if (md) fPicture = gClient->GetPicture(md->fFilename);
212 
214 }
215 
216 ////////////////////////////////////////////////////////////////////////////////
217 /// Save the pattern select widget as a C++ statement(s) on output stream out
218 
219 void TGedMarkerSelect::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
220 {
221  out <<" TGedMarkerSelect *";
222  out << GetName() << " = new TGedMarkerSelect(" << fParent->GetName()
223  << "," << fMarkerStyle << "," << WidgetId() << ");" << std::endl;
224 }
const TGWindow * fParent
Definition: TGWindow.h:43
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:221
virtual void DoRedraw()
Draw selected marker type as current one.
Int_t fBorderWidth
Definition: TGFrame.h:156
short Style_t
Definition: RtypesCore.h:76
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:487
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
const TGPicture * fPicture
const char Option_t
Definition: RtypesCore.h:62
TH1 * h
Definition: legend2.C:5
Bool_t IsEnabled() const
Definition: TGWidget.h:87
void SetMarkerStyle(Style_t pattern)
Set marker.
virtual TList * GetList() const
Definition: TGFrame.h:385
#define gClient
Definition: TGClient.h:174
virtual void SetLayoutManager(TGLayoutManager *l)
Set the layout manager for the composite frame.
Definition: TGFrame.cxx:982
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
static const TGGC & GetDefaultGC()
Return default graphics context.
Definition: TGButton.cxx:420
Int_t MK_MSG(EWidgetMessageTypes msg, EWidgetMessageTypes submsg)
TGedMarkerSelect(const TGWindow *p, Style_t markerStyle, Int_t id)
Create and show marker popup window.
ClassImp(TGedMarkerSelect) ClassImp(TGedMarkerPopup) struct MarkerDescription_t
Int_t fWidgetId
Definition: TGWidget.h:64
void Draw(Option_t *="")
Default Draw method for all objects.
Definition: TGPicture.h:67
Double_t x[n]
Definition: legend1.C:17
ULong_t Pixel_t
Definition: GuiTypes.h:41
void Class()
Definition: Class.C:29
virtual void MarkerSelected(Style_t marker=0)
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition: TGClient.cxx:306
virtual void SetPopup(TGedPopup *p)
virtual void SendMessage(const TGWindow *w, Long_t msg, Long_t parm1, Long_t parm2)
Send message (i.e.
Definition: TGFrame.cxx:627
virtual void SetBackgroundColor(Pixel_t back)
Set background color (override from TGWindow base class).
Definition: TGFrame.cxx:294
const TGWindow * fMsgWindow
Definition: TGWidget.h:66
char * out
Definition: TBase64.cxx:29
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
Process messages generated by the marker popup window.
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
Process messages according to the user input.
virtual ~TGedMarkerPopup()
Destructor.
static MarkerDescription_t * GetMarkerByNumber(Int_t number)
Int_t GET_SUBMSG(Long_t val)
const TGWindow * fMsgWindow
unsigned int UInt_t
Definition: RtypesCore.h:42
TMarker * m
Definition: textangle.C:8
TGFrame * fFrame
Definition: TGLayout.h:125
TString fName
Definition: TGWindow.h:45
#define gVirtualX
Definition: TVirtualX.h:362
virtual void DoRedraw()
Draw separator and arrow.
Int_t GET_MSG(Long_t val)
void EndPopup()
Ungrab pointer and unmap popup window.
Int_t WidgetId() const
Definition: TGWidget.h:86
long Long_t
Definition: RtypesCore.h:50
TGedMarkerPopup(const TGWindow *p, const TGWindow *m, Style_t markerStyle)
Create marker popup window.
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save the pattern select widget as a C++ statement(s) on output stream out.
Double_t y[n]
Definition: legend1.C:17
UInt_t fHeight
Definition: TGFrame.h:151
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1146
Handle_t fId
Definition: TGObject.h:40
TGClient * fClient
Definition: TGObject.h:41
EButtonState fState
Definition: TGButton.h:79
virtual void Draw3dRectangle(UInt_t type, Int_t x, Int_t y, UInt_t w, UInt_t h)
Draw 3D rectangle on the frame border.
Definition: TGFrame.cxx:339
virtual void Cleanup()
Cleanup and delete all objects contained in this composite frame.
Definition: TGFrame.cxx:949
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition: TGButton.cxx:395
static MarkerDescription_t gMarkers[]
GContext_t GetGC() const
Definition: TGGC.h:54
static const TGGC & GetShadowGC()
Get shadow color graphics context.
Definition: TGFrame.cxx:747