Logo ROOT   6.18/05
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
41struct 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
47static 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
70static 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));
99 b->SetToolTipText(gMarkers[i].fName);
100 }
101
102 Resize(65, 94);
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;
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
219void TGedMarkerSelect::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
220{
221 out <<" TGedMarkerSelect *";
222 out << GetName() << " = new TGedMarkerSelect(" << fParent->GetName()
223 << "," << fMarkerStyle << "," << WidgetId() << ");" << std::endl;
224}
void Class()
Definition: Class.C:29
ULong_t Pixel_t
Definition: GuiTypes.h:39
#define b(i)
Definition: RSha256.hxx:100
#define h(i)
Definition: RSha256.hxx:106
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
long Long_t
Definition: RtypesCore.h:50
bool Bool_t
Definition: RtypesCore.h:59
short Style_t
Definition: RtypesCore.h:76
const Bool_t kTRUE
Definition: RtypesCore.h:87
const char Option_t
Definition: RtypesCore.h:62
#define ClassImp(name)
Definition: Rtypes.h:365
@ kButtonDown
Definition: TGButton.h:54
#define gClient
Definition: TGClient.h:166
@ kRaisedFrame
Definition: TGFrame.h:62
@ kSunkenFrame
Definition: TGFrame.h:61
@ kDoubleBorder
Definition: TGFrame.h:63
@ kOwnBackground
Definition: TGFrame.h:69
@ kLHintsLeft
Definition: TGLayout.h:31
XFontStruct * id
Definition: TGX11.cxx:108
static MarkerDescription_t * GetMarkerByNumber(Int_t number)
static MarkerDescription_t gMarkers[]
#define gVirtualX
Definition: TVirtualX.h:345
Int_t MK_MSG(EWidgetMessageTypes msg, EWidgetMessageTypes submsg)
Int_t GET_MSG(Long_t val)
@ kC_MARKERSEL
@ kC_COMMAND
@ kCM_BUTTON
@ kMAR_SELCHANGED
Int_t GET_SUBMSG(Long_t val)
static const TGGC & GetDefaultGC()
Return default graphics context.
Definition: TGButton.cxx:420
EButtonState fState
Definition: TGButton.h:75
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition: TGClient.cxx:308
virtual void SetLayoutManager(TGLayoutManager *l)
Set the layout manager for the composite frame.
Definition: TGFrame.cxx:982
virtual TList * GetList() const
Definition: TGFrame.h:369
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 Cleanup()
Cleanup and delete all objects contained in this composite frame.
Definition: TGFrame.cxx:949
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1146
TGFrame * fFrame
Definition: TGLayout.h:119
UInt_t fHeight
Definition: TGFrame.h:135
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
Int_t fBorderWidth
Definition: TGFrame.h:140
virtual void SetBackgroundColor(Pixel_t back)
Set background color (override from TGWindow base class).
Definition: TGFrame.cxx:294
virtual void SendMessage(const TGWindow *w, Long_t msg, Long_t parm1, Long_t parm2)
Send message (i.e.
Definition: TGFrame.cxx:627
static const TGGC & GetShadowGC()
Get shadow color graphics context.
Definition: TGFrame.cxx:747
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
GContext_t GetGC() const
Definition: TGGC.h:50
TGClient * fClient
Definition: TGObject.h:37
Handle_t fId
Definition: TGObject.h:36
void Draw(Option_t *="")
Default Draw method for all objects.
Definition: TGPicture.h:57
Int_t fWidgetId
Definition: TGWidget.h:58
const TGWindow * fMsgWindow
Definition: TGWidget.h:60
Bool_t IsEnabled() const
Definition: TGWidget.h:81
Int_t WidgetId() const
Definition: TGWidget.h:80
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:221
const TGWindow * fParent
Definition: TGWindow.h:37
TString fName
Definition: TGWindow.h:39
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
Process messages generated by the marker popup window.
TGedMarkerPopup(const TGWindow *p, const TGWindow *m, Style_t markerStyle)
Create marker popup window.
virtual ~TGedMarkerPopup()
Destructor.
void SetMarkerStyle(Style_t pattern)
Set marker.
virtual void DoRedraw()
Draw selected marker type as current one.
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save the pattern select widget as a C++ statement(s) on output stream out.
const TGPicture * fPicture
virtual void MarkerSelected(Style_t marker=0)
TGedMarkerSelect(const TGWindow *p, Style_t markerStyle, Int_t id)
Create and show marker popup window.
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
Process messages according to the user input.
void EndPopup()
Ungrab pointer and unmap popup window.
const TGWindow * fMsgWindow
virtual void DoRedraw()
Draw separator and arrow.
virtual void SetPopup(TGedPopup *p)
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:443
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
auto * m
Definition: textangle.C:8