Logo ROOT  
Reference Guide
TGStatusBar.cxx
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Fons Rademakers 23/01/98
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, 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  This source is based on Xclass95, a Win95-looking GUI toolkit.
14  Copyright (C) 1996, 1997 David Barth, Ricky Ralston, Hector Peraza.
15 
16  Xclass95 is free software; you can redistribute it and/or
17  modify it under the terms of the GNU Library General Public
18  License as published by the Free Software Foundation; either
19  version 2 of the License, or (at your option) any later version.
20 
21 **************************************************************************/
22 
23 //////////////////////////////////////////////////////////////////////////
24 // //
25 // TGStatusBar //
26 // //
27 // Provides a StatusBar widget. //
28 // //
29 //////////////////////////////////////////////////////////////////////////
30 
31 #include "TGStatusBar.h"
32 #include "TGResourcePool.h"
33 #include "TList.h"
34 #include "TVirtualX.h"
35 
36 #include <iostream>
37 
38 const TGFont *TGStatusBar::fgDefaultFont = nullptr;
40 
41 
42 class TGStatusBarPart : public TGHorizontalFrame {
43 friend class TGStatusBar;
44 private:
45  TGString *fStatusInfo; // status text to be displayed in this part
46  Int_t fYt; // y position of text in frame
47  virtual void DoRedraw();
48 
49 public:
51  ~TGStatusBarPart() { delete fStatusInfo; DestroyWindow(); }
52  void SetText(TGString *text);
53  const TGString *GetText() const { return fStatusInfo; }
54 };
55 
56 ////////////////////////////////////////////////////////////////////////////////
57 /// Create statusbar part frame. This frame will contain the text for this
58 /// statusbar part.
59 
60 TGStatusBarPart::TGStatusBarPart(const TGWindow *p, Int_t h, Int_t y, ULong_t back)
62 {
63  fStatusInfo = 0;
64  fYt = y + 1;
65  fHeight = h;
66  MapWindow();
67 
69 }
70 
71 ////////////////////////////////////////////////////////////////////////////////
72 /// Set text in this part of the statusbar.
73 
74 void TGStatusBarPart::SetText(TGString *text)
75 {
76  if (fStatusInfo) delete fStatusInfo;
77  fStatusInfo = text;
78  fClient->NeedRedraw(this);
79 }
80 
81 ////////////////////////////////////////////////////////////////////////////////
82 /// Draw string in statusbar part frame.
83 
84 void TGStatusBarPart::DoRedraw()
85 {
87 
88  if (fStatusInfo)
89  fStatusInfo->Draw(fId, TGStatusBar::GetDefaultGC()(), 3, fYt);
90 }
91 
92 
94 
95 ////////////////////////////////////////////////////////////////////////////////
96 /// Create a status bar widget. By default it consist of one part.
97 /// Multiple parts can be created using SetParts().
98 
100  UInt_t options, ULong_t back) :
101  TGHorizontalFrame(p, w, h, options, back)
102 {
103  fBorderWidth = 2;
104  fStatusPart = new TGStatusBarPart* [1];
105  fParts = new Int_t [1];
106  fXt = new Int_t [1];
107  fParts[0] = 100;
108  fNpart = 1;
109  f3DCorner = kTRUE;
110 
111  int max_ascent, max_descent;
112  gVirtualX->GetFontProperties(GetDefaultFontStruct(), max_ascent, max_descent);
113  int ht = max_ascent + max_descent;
114 
115  fYt = max_ascent;
116 
117  fStatusPart[0] = new TGStatusBarPart(this, ht, fYt);
118  AddFrame(fStatusPart[0]);
119  Resize(w, ht + 5);
120 
121  //fEditDisabled = kEditDisableLayout;
122 }
123 
124 ////////////////////////////////////////////////////////////////////////////////
125 /// Delete status bar widget.
126 
128 {
129  if (!MustCleanup()) {
130  for (int i = 0; i < fNpart; i++) {
131  delete fStatusPart[i];
132  }
133  }
134 
135  delete [] fStatusPart;
136  delete [] fParts;
137  delete [] fXt;
138 }
139 
140 ////////////////////////////////////////////////////////////////////////////////
141 /// Set text in partition partidx in status bar. The TGString is
142 /// adopted by the status bar.
143 
145 {
146  if (partidx < 0 || partidx >= fNpart) {
147  Error("SetText", "partidx out of range (0,%d)", fNpart-1);
148  return;
149  }
150 
151  fStatusPart[partidx]->SetText(text);
152 }
153 
154 ////////////////////////////////////////////////////////////////////////////////
155 /// Set text in partion partidx in status bar.
156 
157 void TGStatusBar::SetText(const char *text, Int_t partidx)
158 {
159  if ((partidx >= 0) && (partidx < fNpart))
160  SetText(new TGString(text), partidx);
161 }
162 
163 ////////////////////////////////////////////////////////////////////////////////
164 /// return text in the part partidx
165 
166 const char *TGStatusBar::GetText(Int_t partidx) const
167 {
168  if (partidx < 0 || partidx >= fNpart) {
169  Error("GetText", "partidx out of range (0,%d)", fNpart-1);
170  return 0;
171  }
172 
173  const TGString *str = fStatusPart[partidx]->GetText();
174  return str->Data();
175 }
176 
177 ////////////////////////////////////////////////////////////////////////////////
178 /// Draw the status bar border (including cute 3d corner).
179 
181 {
182  // Current width is known at this stage so calculate fXt's.
183  int i;
184  for (i = 0; i < fNpart; i++) {
185  if (i == 0)
186  fXt[i] = 0;
187  else
188  fXt[i] = fXt[i-1] + (fWidth * fParts[i-1] / 100);
189  }
190 
191  //TGFrame::DrawBorder();
192  for (i = 0; i < fNpart; i++) {
193  int xmax, xmin = fXt[i];
194  if (i == fNpart-1)
195  xmax = fWidth;
196  else
197  xmax = fXt[i+1] - 2;
198 
199  if (i == fNpart-1) {
200  if (f3DCorner)
201  fStatusPart[i]->MoveResize(fXt[i]+2, 1, xmax - fXt[i] - 15, fHeight - 2);
202  else
203  fStatusPart[i]->MoveResize(fXt[i]+2, 1, xmax - fXt[i], fHeight - 2);
204  } else
205  fStatusPart[i]->MoveResize(fXt[i]+2, 1, xmax - fXt[i] - 4, fHeight - 2);
206 
207  gVirtualX->DrawLine(fId, GetShadowGC()(), xmin, 0, xmax-2, 0);
208  gVirtualX->DrawLine(fId, GetShadowGC()(), xmin, 0, xmin, fHeight-2);
209  gVirtualX->DrawLine(fId, GetHilightGC()(), xmin, fHeight-1, xmax-1, fHeight-1);
210  if (i == fNpart-1)
211  gVirtualX->DrawLine(fId, GetHilightGC()(), xmax-1, fHeight-1, xmax-1, 0);
212  else
213  gVirtualX->DrawLine(fId, GetHilightGC()(), xmax-1, fHeight-1, xmax-1, 1);
214  }
215 
216  // 3d corner...
217  if (f3DCorner) {
218  gVirtualX->DrawLine(fId, GetShadowGC()(), fWidth-3, fHeight-2, fWidth-2, fHeight-3);
219  gVirtualX->DrawLine(fId, GetShadowGC()(), fWidth-4, fHeight-2, fWidth-2, fHeight-4);
220  gVirtualX->DrawLine(fId, GetHilightGC()(), fWidth-5, fHeight-2, fWidth-2, fHeight-5);
221 
222  gVirtualX->DrawLine(fId, GetShadowGC()(), fWidth-7, fHeight-2, fWidth-2, fHeight-7);
223  gVirtualX->DrawLine(fId, GetShadowGC()(), fWidth-8, fHeight-2, fWidth-2, fHeight-8);
224  gVirtualX->DrawLine(fId, GetHilightGC()(), fWidth-9, fHeight-2, fWidth-2, fHeight-9);
225 
226  gVirtualX->DrawLine(fId, GetShadowGC()(), fWidth-11, fHeight-2, fWidth-2, fHeight-11);
227  gVirtualX->DrawLine(fId, GetShadowGC()(), fWidth-12, fHeight-2, fWidth-2, fHeight-12);
228  gVirtualX->DrawLine(fId, GetHilightGC()(), fWidth-13, fHeight-2, fWidth-2, fHeight-13);
229 
230  gVirtualX->DrawLine(fId, GetBckgndGC()(), fWidth-13, fHeight-1, fWidth-1, fHeight-1);
231  gVirtualX->DrawLine(fId, GetBckgndGC()(), fWidth-1, fHeight-1, fWidth-1, fHeight-13);
232  }
233 }
234 
235 ////////////////////////////////////////////////////////////////////////////////
236 /// Redraw status bar.
237 
239 {
240  // calls DrawBorder()
242 
243  for (int i = 0; i < fNpart; i++)
244  fStatusPart[i]->DoRedraw();
245 }
246 
247 ////////////////////////////////////////////////////////////////////////////////
248 /// Divide the status bar in nparts. Size of each part is given in parts
249 /// array (percentual).
250 
251 void TGStatusBar::SetParts(Int_t *parts, Int_t npart)
252 {
253  if (npart < 1) {
254  Warning("SetParts", "must be at least one part");
255  npart = 1;
256  }
257  if (npart > 15) {
258  Error("SetParts", "to many parts (limit is 15)");
259  return;
260  }
261 
262  int i;
263  for (i = 0; i < fNpart; i++)
264  delete fStatusPart[i];
265 
266  delete [] fStatusPart;
267  delete [] fParts;
268  delete [] fXt;
269  fList->Delete();
270 
271  fStatusPart = new TGStatusBarPart* [npart];
272  fParts = new Int_t [npart];
273  fXt = new Int_t [npart];
274 
275  int tot = 0;
276  for (i = 0; i < npart; i++) {
277  fStatusPart[i] = new TGStatusBarPart(this, fHeight, fYt);
278  AddFrame(fStatusPart[i]);
279  fParts[i] = parts[i];
280  tot += parts[i];
281  if (tot > 100)
282  Error("SetParts", "sum of part > 100");
283  }
284  if (tot < 100)
285  fParts[npart-1] += 100 - tot;
286  fNpart = npart;
287 }
288 
289 ////////////////////////////////////////////////////////////////////////////////
290 /// Divide the status bar in npart equal sized parts.
291 
293 {
294  if (npart < 1) {
295  Warning("SetParts", "must be at least one part");
296  npart = 1;
297  }
298  if (npart > 40) {
299  Error("SetParts", "to many parts (limit is 40)");
300  return;
301  }
302 
303  int i;
304  for (i = 0; i < fNpart; i++)
305  delete fStatusPart[i];
306 
307  delete [] fStatusPart;
308  delete [] fParts;
309  delete [] fXt;
310  fList->Delete();
311 
312  fStatusPart = new TGStatusBarPart* [npart];
313  fParts = new Int_t [npart];
314  fXt = new Int_t [npart];
315 
316  int sz = 100/npart;
317  int tot = 0;
318  for (i = 0; i < npart; i++) {
319  fStatusPart[i] = new TGStatusBarPart(this, fHeight, fYt);
320  AddFrame(fStatusPart[i]);
321  fParts[i] = sz;
322  tot += sz;
323  }
324  if (tot < 100)
325  fParts[npart-1] += 100 - tot;
326  fNpart = npart;
327 }
328 
329 ////////////////////////////////////////////////////////////////////////////////
330 /// Return default font structure in use.
331 
333 {
334  if (!fgDefaultFont)
335  fgDefaultFont = gClient->GetResourcePool()->GetStatusFont();
336  return fgDefaultFont->GetFontStruct();
337 }
338 
339 ////////////////////////////////////////////////////////////////////////////////
340 /// Return default graphics context in use.
341 
343 {
344  if (!fgDefaultGC) {
345  fgDefaultGC = new TGGC(*gClient->GetResourcePool()->GetFrameGC());
347  }
348  return *fgDefaultGC;
349 }
350 
351 ////////////////////////////////////////////////////////////////////////////////
352 /// Returns bar part. That allows to put in the bar part
353 /// something more interesting than text ;-)
354 
356 {
357  return ((npart<fNpart) && (npart>=0)) ? (TGCompositeFrame*)fStatusPart[npart] : 0;
358 }
359 
360 ////////////////////////////////////////////////////////////////////////////////
361 /// Return default size.
362 
364 {
365  UInt_t h = fHeight;
366 
367  for (int i = 0; i < fNpart; i++) {
369  }
370  return TGDimension(fWidth, h);
371 }
372 
373 ////////////////////////////////////////////////////////////////////////////////
374 /// Save a status bar widget as a C++ statement(s) on output stream out.
375 
376 void TGStatusBar::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
377 {
378  if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
379 
380  out << std::endl;
381  out << " // status bar" << std::endl;
382 
383  out << " TGStatusBar *";
384  out << GetName() <<" = new TGStatusBar("<< fParent->GetName()
385  << "," << GetWidth() << "," << GetHeight();
386 
389  out <<");" << std::endl;
390  } else {
391  out << "," << GetOptionString() <<");" << std::endl;
392  }
393  } else {
394  out << "," << GetOptionString() << ",ucolor);" << std::endl;
395  }
396  if (option && strstr(option, "keep_names"))
397  out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
398 
399  int i; char quote = '"';
400 
401  if (fNpart > 1) {
402  out << " Int_t parts" << GetName()+5 << "[] = {" << fParts[0];
403 
404  for (i=1; i<fNpart; i++) {
405  out << "," << fParts[i];
406  }
407  out << "};" << std::endl;
408 
409  out << " " << GetName() << "->SetParts(parts" << GetName()+5
410  << "," << fNpart << ");" <<std::endl;
411  }
412  for (i=0; i<fNpart; i++) {
413  if (fStatusPart[i]->GetText()) {
414  out << " " << GetName() << "->SetText(" << quote
415  << fStatusPart[i]->GetText()->GetString()
416  << quote << "," << i << ");" << std::endl;
417  } else {
418  if (!fStatusPart[i]->GetList()->First()) continue;
419  out << " TGCompositeFrame *" << fStatusPart[i]->GetName()
420  << " = " << GetName() << "->GetBarPart(" << i << ");" << std::endl;
421 
422  TGFrameElement *el;
423  TIter next(fStatusPart[i]->GetList());
424 
425  while ((el = (TGFrameElement *) next())) {
426  el->fFrame->SavePrimitive(out, option);
427  out << " " << fStatusPart[i]->GetName() << "->AddFrame("
428  << el->fFrame->GetName();
429  el->fLayout->SavePrimitive(out, option);
430  out << ");" << std::endl;
431  }
432  }
433  }
434 }
TGStatusBar::fXt
Int_t * fXt
Definition: TGStatusBar.h:42
TGStatusBar::SetParts
virtual void SetParts(Int_t npart)
Divide the status bar in npart equal sized parts.
Definition: TGStatusBar.cxx:292
TGFrame::GetHeight
UInt_t GetHeight() const
Definition: TGFrame.h:250
TGStatusBar::GetDefaultGC
static const TGGC & GetDefaultGC()
Return default graphics context in use.
Definition: TGStatusBar.cxx:342
TGFrameElement::fLayout
TGLayoutHints * fLayout
Definition: TGLayout.h:121
TGWindow
Definition: TGWindow.h:31
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TGCompositeFrame::GetList
virtual TList * GetList() const
Definition: TGFrame.h:347
TGDimension
Definition: TGDimension.h:27
Option_t
const char Option_t
Definition: RtypesCore.h:66
TMath::Max
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:212
gVirtualX
#define gVirtualX
Definition: TVirtualX.h:338
TList::Delete
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:470
TString::Data
const char * Data() const
Definition: TString.h:369
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TGFrame::fWidth
UInt_t fWidth
Definition: TGFrame.h:112
TGStatusBar::fYt
Int_t fYt
Definition: TGStatusBar.h:41
FontStruct_t
Handle_t FontStruct_t
Definition: GuiTypes.h:38
xmax
float xmax
Definition: THbookFile.cxx:95
TGStatusBar.h
TObject::Error
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:890
TGFrame::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a frame widget as a C++ statement(s) on output stream out.
Definition: TGFrame.cxx:3192
Int_t
int Int_t
Definition: RtypesCore.h:45
TList.h
TGStatusBar::SetText
virtual void SetText(TGString *text, Int_t partidx=0)
Set text in partition partidx in status bar.
Definition: TGStatusBar.cxx:144
TGFrame::GetDefaultFrameBackground
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition: TGFrame.cxx:668
TVirtualX.h
TGHorizontalFrame
Definition: TGFrame.h:423
text
TText * text
Definition: entrylist_figure1.C:10
TGFrame::MapWindow
virtual void MapWindow()
map window
Definition: TGFrame.h:229
TGFrame::GetWidth
UInt_t GetWidth() const
Definition: TGFrame.h:249
TGCompositeFrame::fList
TList * fList
Definition: TGFrame.h:329
TGFrameElement::fFrame
TGFrame * fFrame
Definition: TGLayout.h:119
TGFrame::GetOptionString
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition: TGFrame.cxx:2465
TGFrame::GetOptions
virtual UInt_t GetOptions() const
Definition: TGFrame.h:222
TGWindow::DestroyWindow
virtual void DestroyWindow()
destroy window
Definition: TGWindow.cxx:191
TGStatusBar
Definition: TGStatusBar.h:29
gClient
#define gClient
Definition: TGClient.h:166
TGStatusBar::fParts
Int_t * fParts
Definition: TGStatusBar.h:39
TGFrame::GetHilightGC
static const TGGC & GetHilightGC()
Get highlight color graphics context.
Definition: TGFrame.cxx:740
kSunkenFrame
@ kSunkenFrame
Definition: GuiTypes.h:383
TGStatusBar::TGStatusBarPart
friend class TGStatusBarPart
Definition: TGStatusBar.h:31
TGStatusBar::TGStatusBar
TGStatusBar(const TGStatusBar &)
TGStatusBar::GetDefaultSize
TGDimension GetDefaultSize() const
Return default size.
Definition: TGStatusBar.cxx:363
TGWindow::kEditDisableGrab
@ kEditDisableGrab
Definition: TGWindow.h:60
xmin
float xmin
Definition: THbookFile.cxx:95
h
#define h(i)
Definition: RSha256.hxx:106
TGWindow::GetName
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:335
TGGC
Definition: TGGC.h:31
TGFrame::Resize
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:590
TGObject::fId
Handle_t fId
Definition: TGObject.h:36
TGStatusBar::fgDefaultGC
static TGGC * fgDefaultGC
Definition: TGStatusBar.h:46
TGStatusBar::GetText
const char * GetText(Int_t partidx=0) const
return text in the part partidx
Definition: TGStatusBar.cxx:166
TGFrame::fBorderWidth
Int_t fBorderWidth
Definition: TGFrame.h:118
TGFont::GetFontHandle
FontH_t GetFontHandle() const
Definition: TGFont.h:192
TGStatusBar::f3DCorner
Bool_t f3DCorner
Definition: TGStatusBar.h:43
TGFrame::SaveUserColor
void SaveUserColor(std::ostream &out, Option_t *)
Save a user color in a C++ macro file - used in SavePrimitive().
Definition: TGFrame.cxx:2438
TGStatusBar::fStatusPart
TGStatusBarPart ** fStatusPart
Definition: TGStatusBar.h:38
y
Double_t y[n]
Definition: legend1.C:17
ULong_t
unsigned long ULong_t
Definition: RtypesCore.h:55
TGStatusBar::DrawBorder
virtual void DrawBorder()
Draw the status bar border (including cute 3d corner).
Definition: TGStatusBar.cxx:180
TGCompositeFrame::MustCleanup
virtual Int_t MustCleanup() const
Definition: TGFrame.h:398
TGLayoutHints::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TGLayout.cxx:1004
TGFrame::GetBckgndGC
static const TGGC & GetBckgndGC()
Get background color graphics context.
Definition: TGFrame.cxx:760
TObject::Warning
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:876
unsigned int
TGCompositeFrame::GetDefaultHeight
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:351
kHorizontalFrame
@ kHorizontalFrame
Definition: GuiTypes.h:382
TGStatusBar::GetBarPart
TGCompositeFrame * GetBarPart(Int_t npart) const
Returns bar part.
Definition: TGStatusBar.cxx:355
TGClient::NeedRedraw
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:373
TGStatusBar::~TGStatusBar
virtual ~TGStatusBar()
Delete status bar widget.
Definition: TGStatusBar.cxx:127
TGObject::fClient
TGClient * fClient
Definition: TGObject.h:37
TGString::Draw
virtual void Draw(Drawable_t id, GContext_t gc, Int_t x, Int_t y)
Draw string.
Definition: TGString.cxx:51
TGFrameElement
Definition: TGLayout.h:112
TGStatusBar::fNpart
Int_t fNpart
Definition: TGStatusBar.h:40
TGFrame::GetShadowGC
static const TGGC & GetShadowGC()
Get shadow color graphics context.
Definition: TGFrame.cxx:750
TIter
Definition: TCollection.h:233
TGStatusBar::DoRedraw
virtual void DoRedraw()
Redraw status bar.
Definition: TGStatusBar.cxx:238
TGStatusBar::fgDefaultFont
static const TGFont * fgDefaultFont
Definition: TGStatusBar.h:45
TGResourcePool.h
TGFont::GetFontStruct
FontStruct_t GetFontStruct() const
Definition: TGFont.h:193
TGFrame::fHeight
UInt_t fHeight
Definition: TGFrame.h:113
TGFrame::fBackground
Pixel_t fBackground
Definition: TGFrame.h:120
TGFont
Definition: TGFont.h:149
TGWindow::fEditDisabled
UInt_t fEditDisabled
Definition: TGWindow.h:40
TGStatusBar::GetDefaultFontStruct
static FontStruct_t GetDefaultFontStruct()
Return default font structure in use.
Definition: TGStatusBar.cxx:332
TGCompositeFrame
Definition: TGFrame.h:324
TGCompositeFrame::AddFrame
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1102
TGStatusBar::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a status bar widget as a C++ statement(s) on output stream out.
Definition: TGStatusBar.cxx:376
TGString
Definition: TGString.h:30
TGGC::SetFont
void SetFont(FontH_t v)
Set font.
Definition: TGGC.cxx:410
TGWindow::fParent
const TGWindow * fParent
Definition: TGWindow.h:36
kChildFrame
@ kChildFrame
Definition: GuiTypes.h:379
int
TGFrame::DoRedraw
virtual void DoRedraw()
Redraw the frame.
Definition: TGFrame.cxx:415