ROOT  6.06/09
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 
15 Created by the TControlBar. Not for general consumption.
16 */
17 
18 #include "TControlBarButton.h"
19 #include "TCanvas.h"
20 #include "TError.h"
21 #include "TApplication.h"
22 
23 #include <ctype.h>
24 
25 const char *kBStr = "BUTTON";
26 const char *kDStr = "DRAWNBUTTON";
27 const char *kSStr = "SEPARATOR";
28 
29 
31 
32 ////////////////////////////////////////////////////////////////////////////////
33 /// Default control bar button ctor.
34 
36 {
37  fType = 0;
38 }
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 /// Create control bar button.
42 
43 TControlBarButton::TControlBarButton(const char *label, const char *action,
44  const char *hint, const char *type)
45  : TNamed(label, hint)
46 {
47  SetType(type);
48  SetAction(action);
49 }
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Execute control bar button command.
53 
55 {
56  if (!fAction.IsNull()) {
57 
59 
60  if (gPad) gPad->Update();
61  }
62 }
63 
64 ////////////////////////////////////////////////////////////////////////////////
65 /// Set action to be executed by this button.
66 
67 void TControlBarButton::SetAction(const char *action)
68 {
69  if (action) {
70  char *s = Strip(action);
71  fAction = s;
72  delete [] s;
73  } else
74  Error("SetAction", "action missing");
75 }
76 
77 
78 ////////////////////////////////////////////////////////////////////////////////
79 /// Set button type. Type can be either "button", "drawnbutton" or
80 /// "separator". String is case insensitive. Default is "button".
81 
83 {
84  fType = kButton;
85 
86  if (type && *type) {
87  if (!strcasecmp(type, kBStr))
88  fType = kButton;
89  else if (!strcasecmp(type, kDStr))
91  else if (!strcasecmp(type, kSStr))
92  fType = kSeparator;
93  else
94  Error("SetType", "unknown type '%s' !\n\t(choice of: %s, %s, %s)",
95  type, kBStr, kDStr, kSStr);
96  }
97 }
98 
99 ////////////////////////////////////////////////////////////////////////////////
100 /// Set button type. Type can be either kButton, kDrawnButton or kSeparator.
101 /// Default is kButton.
102 
104 {
105  switch (type) {
106 
107  case kButton:
108  case kDrawnButton:
109  case kSeparator:
110  fType = type;
111  break;
112 
113  default:
114  fType = kButton;
115  Error("SetType", "unknown type: %d !\n\t(choice of: %d, %d, %d)",
117  }
118 }
virtual Long_t ProcessLine(const char *line, Bool_t sync=kFALSE, Int_t *error=0)
Process a single command line, either a C++ statement or an interpreter command starting with a "...
const char * kDStr
int Int_t
Definition: RtypesCore.h:41
R__EXTERN TApplication * gApplication
Definition: TApplication.h:171
virtual void SetType(const char *type)
Set button type.
const char * Data() const
Definition: TString.h:349
const char * kBStr
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
virtual void Action()
Execute control bar button command.
char * Strip(const char *str, char c= ' ')
Strip leading and trailing c (blanks by default) from a string.
Definition: TString.cxx:2477
ClassImp(TControlBarButton) TControlBarButton
Default control bar button ctor.
Bool_t IsNull() const
Definition: TString.h:387
virtual void SetAction(const char *action)
Set action to be executed by this button.
PyObject * fType
int type
Definition: TGX11.cxx:120
const char * kSStr
#define gPad
Definition: TVirtualPad.h:288
Created by the TControlBar.