Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 "TGButton.h"
35#include "TVirtualX.h"
36
37#include <iostream>
38
41
42struct MarkerDescription_t {
43 const char* fFilename; // xpm file name
44 const char* fName; // type number for tooltip
45 Int_t fNumber; // marker type number
46};
47
48static MarkerDescription_t gMarkers[] = {
49
50 {"marker1.xpm", "1", 1},
51 {"marker6.xpm", "6", 6},
52 {"marker7.xpm", "7", 7},
53 {"marker2.xpm", "2", 2},
54 {"marker3.xpm", "3", 3},
55 {"marker4.xpm", "4", 4},
56 {"marker5.xpm", "5", 5},
57 {"marker20.xpm", "20", 20},
58 {"marker21.xpm", "21", 21},
59 {"marker22.xpm", "22", 22},
60 {"marker23.xpm", "23", 23},
61 {"marker24.xpm", "24", 24},
62 {"marker25.xpm", "25", 25},
63 {"marker26.xpm", "26", 26},
64 {"marker27.xpm", "27", 27},
65 {"marker28.xpm", "28", 28},
66 {"marker29.xpm", "29", 29},
67 {"marker30.xpm", "30", 30},
68 {0, 0, 0},
69};
70
71static MarkerDescription_t* GetMarkerByNumber(Int_t number)
72{
73 for (Int_t i = 0; gMarkers[i].fFilename != 0; i++) {
74 if (gMarkers[i].fNumber == number)
75 return &gMarkers[i];
76 }
77 return 0;
78}
79
80////////////////////////////////////////////////////////////////////////////////
81/// Create marker popup window.
82
85 GetDefaultFrameBackground())
86{
87 TGButton *b;
88 fCurrentStyle = markerStyle;
89
90 Pixel_t white;
91 gClient->GetColorByName("white", white); // white background
92 SetBackgroundColor(white);
93
94 SetLayoutManager(new TGTileLayout(this, 1));
95
96 for (int i = 0; gMarkers[i].fFilename != 0; i++) {
97 AddFrame(b = new TGPictureButton(this, gMarkers[i].fFilename,
99 new TGLayoutHints(kLHintsLeft, 14, 14, 14, 14));
100 b->SetToolTipText(gMarkers[i].fName);
101 }
102
103 Resize(65, 94);
105}
106
107////////////////////////////////////////////////////////////////////////////////
108/// Destructor.
109
111{
112 TGFrameElement *el;
113 TIter next(GetList());
114 while ((el = (TGFrameElement *)next())) {
115 if (el->fFrame->InheritsFrom(TGPictureButton::Class()))
116 fClient->FreePicture(((TGPictureButton *)el->fFrame)->GetPicture());
117 }
118 Cleanup();
119}
120
121////////////////////////////////////////////////////////////////////////////////
122/// Process messages generated by the marker popup window.
123
125{
126 if (GET_MSG(msg) == kC_COMMAND && GET_SUBMSG(msg) == kCM_BUTTON) {
128 EndPopup();
129 }
130
131 if (parm2) {
132 // no warning
133 }
134
135 return kTRUE;
136}
137
138////////////////////////////////////////////////////////////////////////////////
139/// Create and show marker popup window.
140
142 : TGedSelect(p, id)
143{
144 fPicture = 0;
145 SetPopup(new TGedMarkerPopup(gClient->GetDefaultRoot(), this, markerStyle));
146 SetMarkerStyle(markerStyle);
147
148}
149
150////////////////////////////////////////////////////////////////////////////////
151/// Process messages according to the user input.
152
154{
155 if (GET_MSG(msg) == kC_MARKERSEL && GET_SUBMSG(msg) == kMAR_SELCHANGED) {
156 SetMarkerStyle(parm2);
157 parm1 = (Long_t)fWidgetId;
159 parm1, parm2);
160 }
161
162 return kTRUE;
163}
164
165////////////////////////////////////////////////////////////////////////////////
166/// Draw selected marker type as current one.
167
169{
171
172 Int_t x, y;
173 UInt_t w, h;
174
175 if (IsEnabled()) {
176 // pattern rectangle
177
178 x = fBorderWidth + 2;
179 y = fBorderWidth + 2; // 1;
180 h = fHeight - (fBorderWidth * 2) - 4; // -3; // 14
181 w = h;
182 if (fState == kButtonDown) {
183 ++x; ++y;
184 }
185 gVirtualX->DrawRectangle(fId, GetShadowGC()(), x, y, w - 1, h - 1);
186
187 if (fPicture != 0) fPicture->Draw(fId, fDrawGC->GetGC(), x + 1, y + 1);
188 } else { // sunken rectangle
189 x = fBorderWidth + 2;
190 y = fBorderWidth + 2; // 1;
191 w = 42;
192 h = fHeight - (fBorderWidth * 2) - 4; // 3;
194 }
195}
196
197////////////////////////////////////////////////////////////////////////////////
198/// Set marker.
199
201{
202 fMarkerStyle = markerStyle;
203 gClient->NeedRedraw(this);
204
205 if (fPicture) {
206 gClient->FreePicture(fPicture);
207 fPicture = 0;
208 }
209
210 MarkerDescription_t *md = GetMarkerByNumber(fMarkerStyle);
211
212 if (md) fPicture = gClient->GetPicture(md->fFilename);
213
215}
216
217////////////////////////////////////////////////////////////////////////////////
218/// Save the pattern select widget as a C++ statement(s) on output stream out
219
220void TGedMarkerSelect::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
221{
222 out <<" TGedMarkerSelect *";
223 out << GetName() << " = new TGedMarkerSelect(" << fParent->GetName()
224 << "," << fMarkerStyle << "," << WidgetId() << ");" << std::endl;
225}
@ kRaisedFrame
Definition GuiTypes.h:384
@ kSunkenFrame
Definition GuiTypes.h:383
@ kDoubleBorder
Definition GuiTypes.h:385
@ kOwnBackground
Definition GuiTypes.h:391
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
#define b(i)
Definition RSha256.hxx:100
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
long Long_t
Definition RtypesCore.h:54
short Style_t
Definition RtypesCore.h:80
const Bool_t kTRUE
Definition RtypesCore.h:91
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
@ kButtonDown
Definition TGButton.h:54
#define gClient
Definition TGClient.h:166
@ kLHintsLeft
Definition TGLayout.h:31
XFontStruct * id
Definition TGX11.cxx:109
static MarkerDescription_t * GetMarkerByNumber(Int_t number)
static MarkerDescription_t gMarkers[]
#define gVirtualX
Definition TVirtualX.h:338
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:423
EButtonState fState
Definition TGButton.h:75
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition TGClient.cxx:307
virtual void SetLayoutManager(TGLayoutManager *l)
Set the layout manager for the composite frame.
Definition TGFrame.cxx:985
virtual TList * GetList() const
Definition TGFrame.h:346
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1102
virtual void Cleanup()
Cleanup and delete all objects contained in this composite frame.
Definition TGFrame.cxx:952
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1149
TGFrame * fFrame
Definition TGLayout.h:119
UInt_t fHeight
Definition TGFrame.h:112
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:342
Int_t fBorderWidth
Definition TGFrame.h:117
virtual void SetBackgroundColor(Pixel_t back)
Set background color (override from TGWindow base class).
Definition TGFrame.cxx:297
virtual void SendMessage(const TGWindow *w, Long_t msg, Long_t parm1, Long_t parm2)
Send message (i.e.
Definition TGFrame.cxx:630
static const TGGC & GetShadowGC()
Get shadow color graphics context.
Definition TGFrame.cxx:750
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition TGFrame.cxx:590
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
Pixmap_t GetPicture() const
Definition TGPicture.h:65
Int_t fWidgetId
Definition TGWidget.h:56
const TGWindow * fMsgWindow
Definition TGWidget.h:58
Bool_t IsEnabled() const
Definition TGWidget.h:79
Int_t WidgetId() const
Definition TGWidget.h:78
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:335
const TGWindow * fParent
Definition TGWindow.h:36
TString fName
Definition TGWindow.h:38
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:445
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
auto * m
Definition textangle.C:8