//------------------------------------------------------------------------------ // gui_Button class -- // (C) Piero Giubilato 2008, Berkeley Lab -- //------------------------------------------------------------------------------ //______________________________________________________________________________ // {Trace} // [File name] "gui_Button.cpp" // [Author] "Piero Giubilato" // [Version] "0.7" // [Modified by] "Piero Giubilato" // [Last revision] "20 Aug 2008" // [Language] "C++" // [Compiler] "Visual C++ 8.x 9.x" // [Member of] "Cool SEAL" // [Project] "SEAL" // [Description] "Source for the gui_Button class" // [Key documentation] // "Visual C++ Reference Help" // "Root reference guide" // {Trace} //______________________________________________________________________________ // Standard component // Root Component #include "TSystem.h" // Application component #include "global.h" #include "gui_Button.h" // CINT Preprocessor class import definition ClassImp(gui_Button) //______________________________________________________________________________ gui_Button::gui_Button(const char* label, UInt_t left, UInt_t top, UInt_t width, UInt_t height, UInt_t behaviour) { // Default constructor. gui_Buttons provides an interface layer that // integrates a root TGTextButton together with all the code necesary to // manage the signal system implemented to handle the TGTextButton events. // // 'label' is the text appearing into the button // 'left', 'top', 'width', 'height' set the position and size of the button // 'behaviour' sets the button behaviour ('km_Button', 'km_Latch'), see // btn_Mode for further info. // Debug dbg_Print("gui_Button::gui_Button:()", DBG_LVL_ZERO); // Sets up the button Init(label, left, top, width, height); // Sets up the behaviour btn_Mode(behaviour); } /* //______________________________________________________________________________ gui_Button(const gui_Button&) { // Copy Constructor dbg_Print("gui_Button::gui_Button: copy constructor", DBG_LVL_ZERO); } //______________________________________________________________________________ const gui_Button& operator=(const gui_Button&) { // Operator= dbg_Print("gui_Button::operator=: copy operator", DBG_LVL_ZERO); } */ //______________________________________________________________________________ gui_Button::~gui_Button() { // Default destructor. dbg_Print("gui_Button::~gui_Button:()", DBG_LVL_ZERO); // Removes the root object from the root graphical server Container()->RemoveFrame(button); button->DestroyWindow(); // Deletes the root object delete button; } //______________________________________________________________________________ void gui_Button::Init(const char* label, UInt_t left, UInt_t top, UInt_t width, UInt_t height) { // Creates a layer over a root button dbg_Print("gui_Button::Init:(default)", DBG_LVL_MAKE); // Initializes the root button button = new TGTextButton(Container(), label); // Connects it to the button handler function button->Connect(button, "Clicked()", "gui_Button", this, "btn_Do()"); // Renders the button into the frame and adds it to the window Container()->AddFrame(button, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0)); button->SetWrapLength(-1); MoveResize(left, top, width, height); // Also update the container // Sets the mechanical dafault status button_Default = false; } //______________________________________________________________________________ UInt_t gui_Button::btn_Mode() const { // Returns current button mode return button_Mode; } //______________________________________________________________________________ UInt_t gui_Button::btn_Mode(UInt_t value) { // Sets the mechanical behaviour of the button through the 'Action' param. // 'Action' = km_Button means that after the call of the 'btn_Status()' method // the status of the button will be reset to the default value, while // 'Action' = km_Latch means that the status of the button will not change // until another user press. // Assigns the value button_Mode = value; // Returns current value return button_Mode; } //______________________________________________________________________________ bool gui_Button::btn_Default() const { // Returns the current button status return button_Default; } //______________________________________________________________________________ bool gui_Button::btn_Default(bool value) { // Sets the default status of the button. button_Default = value; // Returns current value return button_Default; } //______________________________________________________________________________ bool gui_Button::btn_Status() { // Returns the current status of the button. See the 'btn_Mode' method for // more information on how the call to this method influence the button // status itself. // Frees the gui system gSystem->ProcessEvents(); // Assigns the value (resets it in case of button mode) bool answer = button_Status; if (button_Mode == km_Button) button_Status = button_Default; // Returns the value return answer; } //______________________________________________________________________________ bool gui_Button::btn_Status(bool value) { // Sets the current status of the button. button_Status = value; // Returns current value return button_Status; } //______________________________________________________________________________ void gui_Button::btn_Do() { // This function is called whenever the button is pressed, as it has been // linked to the associated root TGTextButton when it was instantiated. dbg_Print("gui_Button::btn_Do: button pressed!", DBG_LVL_FLOW) // Calls the associated handler, if anyone, passing the ID as argument gui_Object::task_Call(gui_Object::obj_Id()); // Updates the status of the button for LabView like style button_Status = !button_Status; } //______________________________________________________________________________ const TGTextButton* gui_Button::Root() const { // Returns the pointer to the embedded root object return button; } //______________________________________________________________________________ void gui_Button::MoveResize(UInt_t left, UInt_t top, UInt_t width, UInt_t height) { // Moves and resizes the button button->MoveResize(left, top, width, height); // Stores the new datas obj_Left = left; obj_Top = top; obj_Width = width; obj_Height = height; // Paint Update(); } //______________________________________________________________________________ void gui_Button::color_Set(UInt_t foreColor, UInt_t backColor) { // Moves and resizes the button button->SetForegroundColor(foreColor); button->SetBackgroundColor(backColor); // Stores the new datas obj_foreColor = foreColor; obj_backColor = backColor; // Refresh the graphical container Update(); } //______________________________________________________________________________ void gui_Button::Text(const char* text) { // Sets the button caption button->SetText(text); // Stores the new data obj_Text.Form(text); } //______________________________________________________________________________ const TString gui_Button::Text() const { // Returns the button text return obj_Text; } //______________________________________________________________________________ void gui_Button::fontBold(bool bold) { // Sets the boldness of the button text (true = bold) // Retrieves the font structure TGFontPool* pool = gClient->GetFontPool(); Int_t kFontWeight = (bold == true) ? kFontWeightBold : kFontWeightNormal; TGFont* font = pool->GetFont("helvetica", -12, kFontWeight, kFontSlantRoman); FontStruct_t ft = font->GetFontStruct(); // Sets the font into the button button->SetFont(ft, false); // Stores the new data obj_fontBold = bold; // Refresh the graphical container Update(); } //______________________________________________________________________________ bool gui_Button::fontBold() const { // Returns the boldness of the button text return obj_fontBold; }