Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
38const TGFont *TGStatusBar::fgDefaultFont = nullptr;
40
41
42class TGStatusBarPart : public TGHorizontalFrame {
43friend class TGStatusBar;
44private:
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
49public:
50 TGStatusBarPart(const TGWindow *p, Int_t h, Int_t y, ULong_t back = GetDefaultFrameBackground());
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
60TGStatusBarPart::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
74void 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
84void 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;
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);
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
157void 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
166const 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
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);
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);
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();
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
376void TGStatusBar::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
377{
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}
@ kChildFrame
Definition GuiTypes.h:379
@ kSunkenFrame
Definition GuiTypes.h:383
@ kHorizontalFrame
Definition GuiTypes.h:382
Handle_t FontStruct_t
Pointer to font structure.
Definition GuiTypes.h:39
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
unsigned long ULong_t
Definition RtypesCore.h:55
const Bool_t kTRUE
Definition RtypesCore.h:91
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:187
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:231
#define gClient
Definition TGClient.h:166
float xmin
float xmax
#define gVirtualX
Definition TVirtualX.h:338
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition TGClient.cxx:371
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 Int_t MustCleanup() const
Definition TGFrame.h:397
TList * fList
Definition TGFrame.h:328
virtual UInt_t GetDefaultHeight() const
Definition TGFrame.h:350
FontStruct_t GetFontStruct() const
Definition TGFont.h:193
FontH_t GetFontHandle() const
Definition TGFont.h:192
TGLayoutHints * fLayout
Definition TGLayout.h:121
TGFrame * fFrame
Definition TGLayout.h:119
virtual void DoRedraw()
Redraw the frame.
Definition TGFrame.cxx:415
UInt_t fHeight
Definition TGFrame.h:112
Int_t fBorderWidth
Definition TGFrame.h:117
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
static const TGGC & GetHilightGC()
Get highlight color graphics context.
Definition TGFrame.cxx:740
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition TGFrame.cxx:668
virtual UInt_t GetOptions() const
Definition TGFrame.h:221
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition TGFrame.cxx:2465
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
UInt_t fWidth
Definition TGFrame.h:111
UInt_t GetHeight() const
Definition TGFrame.h:249
virtual void MapWindow()
map window
Definition TGFrame.h:228
UInt_t GetWidth() const
Definition TGFrame.h:248
void SaveUserColor(std::ostream &out, Option_t *)
Save a user color in a C++ macro file - used in SavePrimitive().
Definition TGFrame.cxx:2438
Pixel_t fBackground
Definition TGFrame.h:119
static const TGGC & GetBckgndGC()
Get background color graphics context.
Definition TGFrame.cxx:760
Definition TGGC.h:31
void SetFont(FontH_t v)
Set font.
Definition TGGC.cxx:410
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
TGClient * fClient
Definition TGObject.h:37
Handle_t fId
Definition TGObject.h:36
virtual ~TGStatusBar()
Delete status bar widget.
static FontStruct_t GetDefaultFontStruct()
Return default font structure in use.
TGDimension GetDefaultSize() const
Return default size.
Int_t * fParts
Definition TGStatusBar.h:39
static const TGGC & GetDefaultGC()
Return default graphics context in use.
const char * GetText(Int_t partidx=0) const
return text in the part partidx
Int_t * fXt
Definition TGStatusBar.h:42
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a status bar widget as a C++ statement(s) on output stream out.
static const TGFont * fgDefaultFont
Definition TGStatusBar.h:45
virtual void DoRedraw()
Redraw status bar.
TGCompositeFrame * GetBarPart(Int_t npart) const
Returns bar part.
virtual void SetText(TGString *text, Int_t partidx=0)
Set text in partition partidx in status bar.
static TGGC * fgDefaultGC
Definition TGStatusBar.h:46
virtual void SetParts(Int_t npart)
Divide the status bar in npart equal sized parts.
Bool_t f3DCorner
Definition TGStatusBar.h:43
TGStatusBar(const TGStatusBar &)=delete
friend class TGStatusBarPart
Definition TGStatusBar.h:31
TGStatusBarPart ** fStatusPart
Definition TGStatusBar.h:38
virtual void DrawBorder()
Draw the status bar border (including cute 3d corner).
virtual void Draw(Drawable_t id, GContext_t gc, Int_t x, Int_t y)
Draw string.
Definition TGString.cxx:51
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:335
const TGWindow * fParent
Definition TGWindow.h:36
@ kEditDisableGrab
Definition TGWindow.h:60
virtual void DestroyWindow()
destroy window
Definition TGWindow.cxx:191
UInt_t fEditDisabled
Definition TGWindow.h:40
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:470
const char * Data() const
Definition TString.h:369
TText * text
Double_t y[n]
Definition legend1.C:17
Short_t Max(Short_t a, Short_t b)
Definition TMathBase.h:212