//------------------------------------------------------------------------------ // gui class for check buttons -- // (C) Piero Giubilato 2008-2010, Berkeley Lab -- //------------------------------------------------------------------------------ //______________________________________________________________________________ // {Trace} // [File name] "gui_Check.cpp" // [Author] "Devis Contarato, Piero Giubilato" // [Version] "0.7" // [Modified by] "Devis Contarato" // [Last revision] "22 Jan 2009" // [Language] "C++" // [Compiler] "Visual C++ 8.x 9.x" // [Member of] "Cool SEAL" // [Project] "SEAL" // [Description] "Source for the gui_Check 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_Check.h" // CINT Preprocessor class import definition ClassImp(gui_Check) //______________________________________________________________________________ gui_Check::gui_Check(const char* label, UInt_t left, UInt_t top, UInt_t width, UInt_t height) { // Default constructor. gui_Check provides an interface layer that // integrates a root TGCheckButton together with all the code necessary to // manage the signal system implemented to handle the TGCheckButton events. // // 'label' is the text appearing next to the check button // 'left', 'top', 'width', 'height' set the position and size of the button // 'evn_Hnd' is a function pointer pointing to the callback function // provided to handle the event (must be a void f(void)). // Debug dbg_Print("gui_Check::gui_Check:(default)", DBG_LVL_ZERO); // Sets up the button Init(label, left, top, width, height); } //______________________________________________________________________________ gui_Check::~gui_Check() { // Default destructor. dbg_Print("gui_Check::gui_Check:()", DBG_LVL_ZERO); // Removes the root object from the root graphical server Container()->RemoveFrame(check); check->DestroyWindow(); // Deletes the root object delete check; } //______________________________________________________________________________ void gui_Check::Init(const char* label, UInt_t left, UInt_t top, UInt_t width, UInt_t height) { // Creates a layer over a root check button dbg_Print("gui_Check::Init:(default)", DBG_LVL_MAKE); // Initializes the root check button check = new TGCheckButton(Container(), label); // Connects it to the button handler function check->Connect(check, "Clicked()", "gui_Check", this, "chk_Do()"); // Renders the button into the frame and adds it to the window Container()->AddFrame(check, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0)); check->SetWrapLength(-1); MoveResize(left, top, width, height); // This also update the container // Sets the mechanical default status; default false---> unchecked check_Default = false; check_Status = check_Default; } //______________________________________________________________________________ bool gui_Check::chk_Default() const { // Returns the current button status return check_Default; } //______________________________________________________________________________ bool gui_Check::chk_Default(bool value) { // Sets the default status of the check button. check_Default = value; // Returns current value return check_Default; } //______________________________________________________________________________ bool gui_Check::chk_Status() { // Returns the current status of the check button. // Frees the gui system gSystem->ProcessEvents(); // Assigns the value (resets it in case of button mode) bool answer = check_Status; // Returns the value return answer; } //______________________________________________________________________________ bool gui_Check::chk_Status(bool value) { // Sets the current status of the button. check_Status = value; // Returns current value return check_Status; } //______________________________________________________________________________ void gui_Check::chk_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_Check::chk_Do: check button pressed!", DBG_LVL_ZERO) // Updates the status of the button for LabView like style check_Status = !check_Status; // Calls the associated handler, if anyone, passing the ID as argument gui_Object::task_Call(gui_Object::obj_Id()); } //______________________________________________________________________________ const TGCheckButton* gui_Check::Root() const { // Returns the pointer to the embedded root object return check; } //______________________________________________________________________________ void gui_Check::MoveResize(UInt_t left, UInt_t top, UInt_t width, UInt_t height) { // Moves and resizes the button check->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_Check::color_Set(UInt_t foreColor, UInt_t backColor) { // Moves and resizes the check button check->SetForegroundColor(foreColor); check->SetBackgroundColor(backColor); // Stores the new datas obj_foreColor = foreColor; obj_backColor = backColor; // Refresh the graphical container Update(); } //______________________________________________________________________________ void gui_Check::Text(const char* text) { // Sets the check button caption check->SetText(text); // Stores the new data obj_Text.Form(text); } //______________________________________________________________________________ const TString gui_Check::Text() const { // Returns the check utton text return obj_Text; } //______________________________________________________________________________ void gui_Check::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 check button check->SetFont(ft, false); // Stores the new data obj_fontBold = bold; // Refresh the graphical container Update(); } //______________________________________________________________________________ bool gui_Check::fontBold() const { // Returns the boldness of the check button text return obj_fontBold; }