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/** \class TGStatusBar
25 \ingroup guiwidgets
26
27Provides a StatusBar widget.
28
29*/
30
31
32#include "TGStatusBar.h"
33#include "TGResourcePool.h"
34#include "TList.h"
35#include "TVirtualX.h"
36
37#include <iostream>
38
39const TGFont *TGStatusBar::fgDefaultFont = nullptr;
41
42
44friend class TGStatusBar;
45private:
46 TGString *fStatusInfo; // status text to be displayed in this part
47 Int_t fYt; // y position of text in frame
48 void DoRedraw() override;
49
50public:
52 ~TGStatusBarPart() override { delete fStatusInfo; DestroyWindow(); }
53 void SetText(TGString *text);
54 const TGString *GetText() const { return fStatusInfo; }
55};
56
57////////////////////////////////////////////////////////////////////////////////
58/// Create statusbar part frame. This frame will contain the text for this
59/// statusbar part.
60
63{
64 fStatusInfo = 0;
65 fYt = y + 1;
66 fHeight = h;
67 MapWindow();
68
70}
71
72////////////////////////////////////////////////////////////////////////////////
73/// Set text in this part of the statusbar.
74
76{
77 if (fStatusInfo) delete fStatusInfo;
79 fClient->NeedRedraw(this);
80}
81
82////////////////////////////////////////////////////////////////////////////////
83/// Draw string in statusbar part frame.
84
86{
88
89 if (fStatusInfo)
91}
92
93
95
96////////////////////////////////////////////////////////////////////////////////
97/// Create a status bar widget. By default it consist of one part.
98/// Multiple parts can be created using SetParts().
99
101 UInt_t options, Pixel_t back) :
102 TGHorizontalFrame(p, w, h, options, back)
103{
104 fBorderWidth = 2;
105 fStatusPart = new TGStatusBarPart* [1];
106 fParts = new Int_t [1];
107 fXt = new Int_t [1];
108 fParts[0] = 100;
109 fNpart = 1;
111
112 int max_ascent, max_descent;
113 gVirtualX->GetFontProperties(GetDefaultFontStruct(), max_ascent, max_descent);
114 int ht = max_ascent + max_descent;
115
116 fYt = max_ascent;
117
118 fStatusPart[0] = new TGStatusBarPart(this, ht, fYt);
120 Resize(w, ht + 5);
121
122 //fEditDisabled = kEditDisableLayout;
123}
124
125////////////////////////////////////////////////////////////////////////////////
126/// Delete status bar widget.
127
129{
130 if (!MustCleanup()) {
131 for (int i = 0; i < fNpart; i++) {
132 delete fStatusPart[i];
133 }
134 }
135
136 delete [] fStatusPart;
137 delete [] fParts;
138 delete [] fXt;
139}
140
141////////////////////////////////////////////////////////////////////////////////
142/// Set text in partition partidx in status bar. The TGString is
143/// adopted by the status bar.
144
146{
147 if (partidx < 0 || partidx >= fNpart) {
148 Error("SetText", "partidx out of range (0,%d)", fNpart-1);
149 return;
150 }
151
152 fStatusPart[partidx]->SetText(text);
153}
154
155////////////////////////////////////////////////////////////////////////////////
156/// Set text in partion partidx in status bar.
157
158void TGStatusBar::SetText(const char *text, Int_t partidx)
159{
160 if ((partidx >= 0) && (partidx < fNpart))
161 SetText(new TGString(text), partidx);
162}
163
164////////////////////////////////////////////////////////////////////////////////
165/// return text in the part partidx
166
167const char *TGStatusBar::GetText(Int_t partidx) const
168{
169 if (partidx < 0 || partidx >= fNpart) {
170 Error("GetText", "partidx out of range (0,%d)", fNpart-1);
171 return 0;
172 }
173
174 const TGString *str = fStatusPart[partidx]->GetText();
175 return str->Data();
176}
177
178////////////////////////////////////////////////////////////////////////////////
179/// Draw the status bar border (including cute 3d corner).
180
182{
183 // Current width is known at this stage so calculate fXt's.
184 int i;
185 for (i = 0; i < fNpart; i++) {
186 if (i == 0)
187 fXt[i] = 0;
188 else
189 fXt[i] = fXt[i-1] + (fWidth * fParts[i-1] / 100);
190 }
191
192 //TGFrame::DrawBorder();
193 for (i = 0; i < fNpart; i++) {
194 int xmax, xmin = fXt[i];
195 if (i == fNpart-1)
196 xmax = fWidth;
197 else
198 xmax = fXt[i+1] - 2;
199
200 if (i == fNpart-1) {
201 if (f3DCorner)
202 fStatusPart[i]->MoveResize(fXt[i]+2, 1, xmax - fXt[i] - 15, fHeight - 2);
203 else
204 fStatusPart[i]->MoveResize(fXt[i]+2, 1, xmax - fXt[i], fHeight - 2);
205 } else
206 fStatusPart[i]->MoveResize(fXt[i]+2, 1, xmax - fXt[i] - 4, fHeight - 2);
207
208 gVirtualX->DrawLine(fId, GetShadowGC()(), xmin, 0, xmax-2, 0);
209 gVirtualX->DrawLine(fId, GetShadowGC()(), xmin, 0, xmin, fHeight-2);
210 gVirtualX->DrawLine(fId, GetHilightGC()(), xmin, fHeight-1, xmax-1, fHeight-1);
211 if (i == fNpart-1)
212 gVirtualX->DrawLine(fId, GetHilightGC()(), xmax-1, fHeight-1, xmax-1, 0);
213 else
214 gVirtualX->DrawLine(fId, GetHilightGC()(), xmax-1, fHeight-1, xmax-1, 1);
215 }
216
217 // 3d corner...
218 if (f3DCorner) {
219 gVirtualX->DrawLine(fId, GetShadowGC()(), fWidth-3, fHeight-2, fWidth-2, fHeight-3);
220 gVirtualX->DrawLine(fId, GetShadowGC()(), fWidth-4, fHeight-2, fWidth-2, fHeight-4);
221 gVirtualX->DrawLine(fId, GetHilightGC()(), fWidth-5, fHeight-2, fWidth-2, fHeight-5);
222
223 gVirtualX->DrawLine(fId, GetShadowGC()(), fWidth-7, fHeight-2, fWidth-2, fHeight-7);
224 gVirtualX->DrawLine(fId, GetShadowGC()(), fWidth-8, fHeight-2, fWidth-2, fHeight-8);
225 gVirtualX->DrawLine(fId, GetHilightGC()(), fWidth-9, fHeight-2, fWidth-2, fHeight-9);
226
227 gVirtualX->DrawLine(fId, GetShadowGC()(), fWidth-11, fHeight-2, fWidth-2, fHeight-11);
228 gVirtualX->DrawLine(fId, GetShadowGC()(), fWidth-12, fHeight-2, fWidth-2, fHeight-12);
229 gVirtualX->DrawLine(fId, GetHilightGC()(), fWidth-13, fHeight-2, fWidth-2, fHeight-13);
230
231 gVirtualX->DrawLine(fId, GetBckgndGC()(), fWidth-13, fHeight-1, fWidth-1, fHeight-1);
232 gVirtualX->DrawLine(fId, GetBckgndGC()(), fWidth-1, fHeight-1, fWidth-1, fHeight-13);
233 }
234}
235
236////////////////////////////////////////////////////////////////////////////////
237/// Redraw status bar.
238
240{
241 // calls DrawBorder()
243
244 for (int i = 0; i < fNpart; i++)
245 fStatusPart[i]->DoRedraw();
246}
247
248////////////////////////////////////////////////////////////////////////////////
249/// Divide the status bar in nparts. Size of each part is given in parts
250/// array (percentual).
251
253{
254 if (npart < 1) {
255 Warning("SetParts", "must be at least one part");
256 npart = 1;
257 }
258 if (npart > 15) {
259 Error("SetParts", "to many parts (limit is 15)");
260 return;
261 }
262
263 int i;
264 for (i = 0; i < fNpart; i++)
265 delete fStatusPart[i];
266
267 delete [] fStatusPart;
268 delete [] fParts;
269 delete [] fXt;
270 fList->Delete();
271
272 fStatusPart = new TGStatusBarPart* [npart];
273 fParts = new Int_t [npart];
274 fXt = new Int_t [npart];
275
276 int tot = 0;
277 for (i = 0; i < npart; i++) {
278 fStatusPart[i] = new TGStatusBarPart(this, fHeight, fYt);
280 fParts[i] = parts[i];
281 tot += parts[i];
282 if (tot > 100)
283 Error("SetParts", "sum of part > 100");
284 }
285 if (tot < 100)
286 fParts[npart-1] += 100 - tot;
287 fNpart = npart;
288}
289
290////////////////////////////////////////////////////////////////////////////////
291/// Divide the status bar in npart equal sized parts.
292
294{
295 if (npart < 1) {
296 Warning("SetParts", "must be at least one part");
297 npart = 1;
298 }
299 if (npart > 40) {
300 Error("SetParts", "to many parts (limit is 40)");
301 return;
302 }
303
304 int i;
305 for (i = 0; i < fNpart; i++)
306 delete fStatusPart[i];
307
308 delete [] fStatusPart;
309 delete [] fParts;
310 delete [] fXt;
311 fList->Delete();
312
313 fStatusPart = new TGStatusBarPart* [npart];
314 fParts = new Int_t [npart];
315 fXt = new Int_t [npart];
316
317 int sz = 100/npart;
318 int tot = 0;
319 for (i = 0; i < npart; i++) {
320 fStatusPart[i] = new TGStatusBarPart(this, fHeight, fYt);
322 fParts[i] = sz;
323 tot += sz;
324 }
325 if (tot < 100)
326 fParts[npart-1] += 100 - tot;
327 fNpart = npart;
328}
329
330////////////////////////////////////////////////////////////////////////////////
331/// Return default font structure in use.
332
334{
335 if (!fgDefaultFont)
336 fgDefaultFont = gClient->GetResourcePool()->GetStatusFont();
338}
339
340////////////////////////////////////////////////////////////////////////////////
341/// Return default graphics context in use.
342
344{
345 if (!fgDefaultGC) {
346 fgDefaultGC = new TGGC(*gClient->GetResourcePool()->GetFrameGC());
348 }
349 return *fgDefaultGC;
350}
351
352////////////////////////////////////////////////////////////////////////////////
353/// Returns bar part. That allows to put in the bar part
354/// something more interesting than text ;-)
355
357{
358 return ((npart<fNpart) && (npart>=0)) ? (TGCompositeFrame*)fStatusPart[npart] : 0;
359}
360
361////////////////////////////////////////////////////////////////////////////////
362/// Return default size.
363
365{
366 UInt_t h = fHeight;
367
368 for (int i = 0; i < fNpart; i++) {
370 }
371 return TGDimension(fWidth, h);
372}
373
374////////////////////////////////////////////////////////////////////////////////
375/// Save a status bar widget as a C++ statement(s) on output stream out.
376
377void TGStatusBar::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
378{
380
381 out << std::endl;
382 out << " // status bar" << std::endl;
383
384 out << " TGStatusBar *";
385 out << GetName() <<" = new TGStatusBar("<< fParent->GetName()
386 << "," << GetWidth() << "," << GetHeight();
387
390 out <<");" << std::endl;
391 } else {
392 out << "," << GetOptionString() <<");" << std::endl;
393 }
394 } else {
395 out << "," << GetOptionString() << ",ucolor);" << std::endl;
396 }
397 if (option && strstr(option, "keep_names"))
398 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
399
400 int i; char quote = '"';
401
402 if (fNpart > 1) {
403 out << " Int_t parts" << GetName()+5 << "[] = {" << fParts[0];
404
405 for (i=1; i<fNpart; i++) {
406 out << "," << fParts[i];
407 }
408 out << "};" << std::endl;
409
410 out << " " << GetName() << "->SetParts(parts" << GetName()+5
411 << "," << fNpart << ");" <<std::endl;
412 }
413 for (i=0; i<fNpart; i++) {
414 if (fStatusPart[i]->GetText()) {
415 out << " " << GetName() << "->SetText(" << quote
416 << fStatusPart[i]->GetText()->GetString()
417 << quote << "," << i << ");" << std::endl;
418 } else {
419 if (!fStatusPart[i]->GetList()->First()) continue;
420 out << " TGCompositeFrame *" << fStatusPart[i]->GetName()
421 << " = " << GetName() << "->GetBarPart(" << i << ");" << std::endl;
422
423 TGFrameElement *el;
424 TIter next(fStatusPart[i]->GetList());
425
426 while ((el = (TGFrameElement *) next())) {
427 el->fFrame->SavePrimitive(out, option);
428 out << " " << fStatusPart[i]->GetName() << "->AddFrame("
429 << el->fFrame->GetName();
430 el->fLayout->SavePrimitive(out, option);
431 out << ");" << std::endl;
432 }
433 }
434 }
435}
@ kChildFrame
Definition GuiTypes.h:379
@ kSunkenFrame
Definition GuiTypes.h:383
@ kHorizontalFrame
Definition GuiTypes.h:382
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
Handle_t FontStruct_t
Pointer to font structure.
Definition GuiTypes.h:39
#define h(i)
Definition RSha256.hxx:106
unsigned long ULong_t
Definition RtypesCore.h:55
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:185
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:229
#define gClient
Definition TGClient.h:157
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t TPoint TPoint const char text
float xmin
float xmax
#define gVirtualX
Definition TVirtualX.h:338
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition TGClient.cxx:372
The base class for composite widgets (menu bars, list boxes, etc.).
Definition TGFrame.h:287
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
virtual TList * GetList() const
Definition TGFrame.h:310
Int_t MustCleanup() const override
Definition TGFrame.h:360
UInt_t GetDefaultHeight() const override
Definition TGFrame.h:314
TList * fList
container of frame elements
Definition TGFrame.h:292
Encapsulate fonts used in the GUI system.
Definition TGFont.h:140
FontStruct_t GetFontStruct() const
Definition TGFont.h:184
FontH_t GetFontHandle() const
Definition TGFont.h:183
TGLayoutHints * fLayout
Definition TGLayout.h:114
TGFrame * fFrame
Definition TGLayout.h:112
void MoveResize(Int_t x, Int_t y, UInt_t w=0, UInt_t h=0) override
Move and/or resize the frame.
Definition TGFrame.cxx:629
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:605
UInt_t fHeight
frame height
Definition TGFrame.h:88
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a frame widget as a C++ statement(s) on output stream out.
Definition TGFrame.cxx:3230
Int_t fBorderWidth
frame border width
Definition TGFrame.h:93
void DoRedraw() override
Redraw the frame.
Definition TGFrame.cxx:430
void MapWindow() override
map window
Definition TGFrame.h:204
static const TGGC & GetHilightGC()
Get highlight color graphics context.
Definition TGFrame.cxx:755
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition TGFrame.cxx:683
virtual UInt_t GetOptions() const
Definition TGFrame.h:197
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition TGFrame.cxx:2506
static const TGGC & GetShadowGC()
Get shadow color graphics context.
Definition TGFrame.cxx:765
UInt_t fWidth
frame width
Definition TGFrame.h:87
UInt_t GetHeight() const
Definition TGFrame.h:225
UInt_t GetWidth() const
Definition TGFrame.h:224
void SaveUserColor(std::ostream &out, Option_t *)
Save a user color in a C++ macro file - used in SavePrimitive().
Definition TGFrame.cxx:2479
Pixel_t fBackground
frame background color
Definition TGFrame.h:95
static const TGGC & GetBckgndGC()
Get background color graphics context.
Definition TGFrame.cxx:775
Encapsulate a graphics context used in the low level graphics.
Definition TGGC.h:22
void SetFont(FontH_t v)
Set font.
Definition TGGC.cxx:411
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:385
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save layout hints as a C++ statement(s) on output stream out.
Definition TGLayout.cxx:975
TGClient * fClient
Connection to display server.
Definition TGObject.h:25
Handle_t fId
X11/Win32 Window identifier.
Definition TGObject.h:24
const TGString * GetText() const
~TGStatusBarPart() override
void DoRedraw() override
Draw string in statusbar part frame.
void SetText(TGString *text)
Set text in this part of the statusbar.
TGStatusBarPart(const TGWindow *p, Int_t h, Int_t y, ULong_t back=GetDefaultFrameBackground())
Create statusbar part frame.
TGString * fStatusInfo
Provides a StatusBar widget.
Definition TGStatusBar.h:21
static FontStruct_t GetDefaultFontStruct()
Return default font structure in use.
Int_t * fParts
size of parts (in percent of total width)
Definition TGStatusBar.h:31
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
x position for each part
Definition TGStatusBar.h:34
~TGStatusBar() override
Delete status bar widget.
void DrawBorder() override
Draw the status bar border (including cute 3d corner).
void DoRedraw() override
Redraw status bar.
static const TGFont * fgDefaultFont
Definition TGStatusBar.h:37
Int_t fYt
y drawing position (depending on font)
Definition TGStatusBar.h:33
TGDimension GetDefaultSize() const override
Return default size.
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.
Int_t fNpart
number of parts
Definition TGStatusBar.h:32
static TGGC * fgDefaultGC
Definition TGStatusBar.h:38
virtual void SetParts(Int_t npart)
Divide the status bar in npart equal sized parts.
Bool_t f3DCorner
draw 3D corner (drawn by default)
Definition TGStatusBar.h:35
TGStatusBar(const TGStatusBar &)=delete
friend class TGStatusBarPart
Definition TGStatusBar.h:23
TGStatusBarPart ** fStatusPart
frames containing statusbar text
Definition TGStatusBar.h:30
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a status bar widget as a C++ statement(s) on output stream out.
TGString wraps a TString and adds some graphics routines like drawing, size of string on screen depen...
Definition TGString.h:20
const char * GetString() const
Definition TGString.h:30
virtual void Draw(Drawable_t id, GContext_t gc, Int_t x, Int_t y)
Draw string.
Definition TGString.cxx:56
ROOT GUI Window base class.
Definition TGWindow.h:23
const TGWindow * fParent
Parent window.
Definition TGWindow.h:28
@ kEditDisableGrab
window grab cannot be edited
Definition TGWindow.h:59
virtual void DestroyWindow()
destroy window
Definition TGWindow.cxx:192
const char * GetName() const override
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:336
UInt_t fEditDisabled
flags used for "guibuilding"
Definition TGWindow.h:32
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:470
const char * Data() const
Definition TString.h:380
Double_t y[n]
Definition legend1.C:17
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:250