TControlBarButton.cxx

Go to the documentation of this file.
00001 // @(#)root/gpad:$Id: TControlBarButton.cxx 20882 2007-11-19 11:31:26Z rdm $
00002 // Author: Nenad Buncic   20/02/96
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 /////////////////////////////////////////////////////////////////////////
00013 //                                                                     //
00014 // TControlBarButton                                                   //
00015 //                                                                     //
00016 // TControlBarButtons are created by the TControlBar. Not for general  //
00017 // consumption.                                                        //
00018 //                                                                     //
00019 /////////////////////////////////////////////////////////////////////////
00020 
00021 #include "TControlBarButton.h"
00022 #include "TCanvas.h"
00023 #include "TError.h"
00024 #include "TApplication.h"
00025 
00026 #include <ctype.h>
00027 
00028 const char *kBStr = "BUTTON";
00029 const char *kDStr = "DRAWNBUTTON";
00030 const char *kSStr = "SEPARATOR";
00031 
00032 
00033 ClassImp(TControlBarButton)
00034 
00035 //_______________________________________________________________________
00036 TControlBarButton::TControlBarButton() : TNamed()
00037 {
00038    // Default controlbar button ctor.
00039 
00040    fType   = 0;
00041 }
00042 
00043 //_______________________________________________________________________
00044 TControlBarButton::TControlBarButton(const char *label, const char *action,
00045                                      const char *hint, const char *type)
00046    : TNamed(label, hint)
00047 {
00048    // Create controlbar button.
00049 
00050    SetType(type);
00051    SetAction(action);
00052 }
00053 
00054 //_______________________________________________________________________
00055 void TControlBarButton::Action()
00056 {
00057    // Execute controlbar button command.
00058 
00059    if (!fAction.IsNull()) {
00060 
00061       gApplication->ProcessLine(fAction.Data());
00062 
00063       if (gPad) gPad->Update();
00064    }
00065 }
00066 
00067 //_______________________________________________________________________
00068 void TControlBarButton::SetAction(const char *action)
00069 {
00070    // Set action to be executed by this button.
00071 
00072    if (action) {
00073       char *s = Strip(action);
00074       fAction = s;
00075       delete [] s;
00076    } else
00077       Error("SetAction", "action missing");
00078 }
00079 
00080 
00081 //_______________________________________________________________________
00082 void TControlBarButton::SetType(const char *type)
00083 {
00084    // Set button type. Type can be either "button", "drawnbutton" or
00085    // "separator". String is case insensitive. Default is "button".
00086 
00087    fType = kButton;
00088 
00089    if (type && *type) {
00090       if (!strcasecmp(type, kBStr))
00091          fType = kButton;
00092       else if (!strcasecmp(type, kDStr))
00093          fType = kDrawnButton;
00094       else if (!strcasecmp(type, kSStr))
00095          fType = kSeparator;
00096       else
00097          Error("SetType", "unknown type '%s' !\n\t(choice of: %s, %s, %s)",
00098                type, kBStr, kDStr, kSStr);
00099    }
00100 }
00101 
00102 //_______________________________________________________________________
00103 void TControlBarButton::SetType(Int_t type)
00104 {
00105    // Set button type. Type can be either kButton, kDrawnButton or kSeparator.
00106    // Default is kButton.
00107 
00108    switch (type) {
00109 
00110       case kButton:
00111       case kDrawnButton:
00112       case kSeparator:
00113          fType = type;
00114          break;
00115 
00116       default:
00117          fType = kButton;
00118          Error("SetType", "unknown type: %d !\n\t(choice of: %d, %d, %d)",
00119                type, kButton, kDrawnButton, kSeparator);
00120    }
00121 }

Generated on Tue Jul 5 14:14:07 2011 for ROOT_528-00b_version by  doxygen 1.5.1