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
71
72////////////////////////////////////////////////////////////////////////////////
73/// Set text in this part of the statusbar.
74
81
82////////////////////////////////////////////////////////////////////////////////
83/// Draw string in statusbar part frame.
84
92
93
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, Pixel_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
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{
147 Error("SetText", "partidx out of range (0,%d)", fNpart-1);
148 return;
149 }
150
152}
153
154////////////////////////////////////////////////////////////////////////////////
155/// Set text in partion partidx in status bar.
156
158{
159 if ((partidx >= 0) && (partidx < fNpart))
161}
162
163////////////////////////////////////////////////////////////////////////////////
164/// return text in the part partidx
165
167{
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
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
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();
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());
346 fgDefaultGC->SetFont(fgDefaultFont->GetFontHandle());
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
359
360////////////////////////////////////////////////////////////////////////////////
361/// Return default size.
362
364{
365 UInt_t h = fHeight;
366
367 for (int i = 0; i < fNpart; i++) {
368 h = std::max(h,fStatusPart[i]->GetDefaultHeight()+1);
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 << "\n // status bar\n";
381
382 out << " TGStatusBar *" << GetName() << " = new TGStatusBar(" << fParent->GetName() << "," << GetWidth() << ","
383 << GetHeight() << extra_args << ");\n";
384
385 if (option && strstr(option, "keep_names"))
386 out << " " << GetName() << "->SetName(\"" << GetName() << "\");\n";
387
388 if (fNpart > 1) {
389 out << " " << GetName() << "->SetParts((Int_t []) {";
390 for (Int_t i = 0; i < fNpart; i++)
391 out << (i == 0 ? "" : ", ") << fParts[i];
392 out << "}, " << fNpart << ");\n";
393 }
394 for (Int_t i = 0; i < fNpart; i++) {
395 if (fStatusPart[i]->GetText()) {
396 out << " " << GetName() << "->SetText(\""
397 << TString(fStatusPart[i]->GetText()->GetString()).ReplaceSpecialCppChars() << "\", " << i << ");\n";
398 } else {
399 if (!fStatusPart[i]->GetList()->First())
400 continue;
401 out << " TGCompositeFrame *" << fStatusPart[i]->GetName() << " = " << GetName() << "->GetBarPart(" << i
402 << ");\n";
403
404 TIter next(fStatusPart[i]->GetList());
405 while (auto el = static_cast<TGFrameElement *>(next())) {
406 el->fFrame->SavePrimitive(out, option);
407 out << " " << fStatusPart[i]->GetName() << "->AddFrame(" << el->fFrame->GetName();
408 el->fLayout->SavePrimitive(out, option);
409 out << ");\n";
410 }
411 }
412 }
413}
@ 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
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
Definition RtypesCore.h:69
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:252
#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:337
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition TGClient.cxx:380
The base class for composite widgets (menu bars, list boxes, etc.).
Definition TGFrame.h:289
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1109
virtual TList * GetList() const
Definition TGFrame.h:312
Int_t MustCleanup() const override
Definition TGFrame.h:362
UInt_t GetDefaultHeight() const override
Definition TGFrame.h:316
TList * fList
container of frame elements
Definition TGFrame.h:294
Encapsulate fonts used in the GUI system.
Definition TGFont.h:140
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:621
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:597
UInt_t fHeight
frame height
Definition TGFrame.h:88
Int_t fBorderWidth
frame border width
Definition TGFrame.h:93
void DoRedraw() override
Redraw the frame.
Definition TGFrame.cxx:422
void MapWindow() override
map window
Definition TGFrame.h:206
static const TGGC & GetHilightGC()
Get highlight color graphics context.
Definition TGFrame.cxx:747
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition TGFrame.cxx:675
static const TGGC & GetShadowGC()
Get shadow color graphics context.
Definition TGFrame.cxx:757
UInt_t fWidth
frame width
Definition TGFrame.h:87
UInt_t GetHeight() const
Definition TGFrame.h:227
TString SaveCtorArgs(std::ostream &out, UInt_t dflt_options=kChildFrame, Bool_t check_white_pixel=kFALSE)
Return options and custom color as constructor args Used in the SavePrimitive methods,...
Definition TGFrame.cxx:2493
UInt_t GetWidth() const
Definition TGFrame.h:226
static const TGGC & GetBckgndGC()
Get background color graphics context.
Definition TGFrame.cxx:767
Encapsulate a graphics context used in the low level graphics.
Definition TGGC.h:22
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:387
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
virtual void Draw(Drawable_t id, GContext_t gc, Int_t x, Int_t y)
Draw string.
Definition TGString.cxx:54
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:190
const char * GetName() const override
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:334
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:467
Basic string class.
Definition TString.h:138
TString & ReplaceSpecialCppChars()
Find special characters which are typically used in printf() calls and replace them by appropriate es...
Definition TString.cxx:1121
Double_t y[n]
Definition legend1.C:17