Logo ROOT  
Reference Guide
TControlBarButton.cxx
Go to the documentation of this file.
1 // @(#)root/gpad:$Id$
2 // Author: Nenad Buncic 20/02/96
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 /** \class TControlBarButton
13 \ingroup gpad
14 This class defines the control bar buttons
15 
16 Created by the TControlBar. Not for general consumption.
17 */
18 
19 #include "TControlBarButton.h"
20 #include "TVirtualPad.h"
21 #include "TError.h"
22 #include "TApplication.h"
23 
24 #include <cctype>
25 
26 const char *kBStr = "BUTTON";
27 const char *kDStr = "DRAWNBUTTON";
28 const char *kSStr = "SEPARATOR";
29 
30 
32 
33 ////////////////////////////////////////////////////////////////////////////////
34 /// Default control bar button ctor.
35 
37 {
38  fType = 0;
39 }
40 
41 ////////////////////////////////////////////////////////////////////////////////
42 /// Create control bar button.
43 
44 TControlBarButton::TControlBarButton(const char *label, const char *action,
45  const char *hint, const char *type)
46  : TNamed(label, hint)
47 {
48  SetType(type);
49  SetAction(action);
50 }
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 /// Execute control bar button command.
54 
56 {
57  if (!fAction.IsNull()) {
58 
60 
61  if (gPad) gPad->Update();
62  }
63 }
64 
65 ////////////////////////////////////////////////////////////////////////////////
66 /// Set action to be executed by this button.
67 
68 void TControlBarButton::SetAction(const char *action)
69 {
70  if (action) {
71  char *s = Strip(action);
72  fAction = s;
73  delete [] s;
74  } else
75  Error("SetAction", "action missing");
76 }
77 
78 
79 ////////////////////////////////////////////////////////////////////////////////
80 /// Set button type. Type can be either "button", "drawnbutton" or
81 /// "separator". String is case insensitive. Default is "button".
82 
84 {
85  fType = kButton;
86 
87  if (type && *type) {
88  if (!strcasecmp(type, kBStr))
89  fType = kButton;
90  else if (!strcasecmp(type, kDStr))
92  else if (!strcasecmp(type, kSStr))
93  fType = kSeparator;
94  else
95  Error("SetType", "unknown type '%s' !\n\t(choice of: %s, %s, %s)",
96  type, kBStr, kDStr, kSStr);
97  }
98 }
99 
100 ////////////////////////////////////////////////////////////////////////////////
101 /// Set button type. Type can be either kButton, kDrawnButton or kSeparator.
102 /// Default is kButton.
103 
105 {
106  switch (type) {
107 
108  case kButton:
109  case kDrawnButton:
110  case kSeparator:
111  fType = type;
112  break;
113 
114  default:
115  fType = kButton;
116  Error("SetType", "unknown type: %d !\n\t(choice of: %d, %d, %d)",
118  }
119 }
kDStr
const char * kDStr
Definition: TControlBarButton.cxx:27
TString::Data
const char * Data() const
Definition: TString.h:369
TControlBarButton::TControlBarButton
TControlBarButton()
Default control bar button ctor.
Definition: TControlBarButton.cxx:36
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TObject::Error
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:890
TControlBarButton::SetType
virtual void SetType(const char *type)
Set button type.
Definition: TControlBarButton.cxx:83
TControlBarButton::kSeparator
@ kSeparator
Definition: TControlBarButton.h:24
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:162
TControlBarButton.h
TControlBarButton::kButton
@ kButton
Definition: TControlBarButton.h:24
kBStr
const char * kBStr
Definition: TControlBarButton.cxx:26
TApplication.h
TApplication::ProcessLine
virtual Long_t ProcessLine(const char *line, Bool_t sync=kFALSE, Int_t *error=0)
TControlBarButton::fType
Int_t fType
button type
Definition: TControlBarButton.h:20
TNamed
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
gApplication
R__EXTERN TApplication * gApplication
Definition: TApplication.h:166
TVirtualPad.h
TControlBarButton::fAction
TString fAction
action to be executed
Definition: TControlBarButton.h:21
TControlBarButton::Action
virtual void Action()
Execute control bar button command.
Definition: TControlBarButton.cxx:55
TString::IsNull
Bool_t IsNull() const
Definition: TString.h:407
TControlBarButton::kDrawnButton
@ kDrawnButton
Definition: TControlBarButton.h:24
TControlBarButton::SetAction
virtual void SetAction(const char *action)
Set action to be executed by this button.
Definition: TControlBarButton.cxx:68
gPad
#define gPad
Definition: TVirtualPad.h:287
kSStr
const char * kSStr
Definition: TControlBarButton.cxx:28
type
int type
Definition: TGX11.cxx:121
TControlBarButton
This class defines the control bar buttons.
Definition: TControlBarButton.h:17
Strip
char * Strip(const char *str, char c=' ')
Strip leading and trailing c (blanks by default) from a string.
Definition: TString.cxx:2454
int
TError.h