//------------------------------------------------------------------------------ // gui text control class -- // (C) Piero Giubilato, Devis Contarato 2008, Berkeley Lab -- //------------------------------------------------------------------------------ //______________________________________________________________________________ // {Trace} // [File name] "gui_Text.cpp" // [Author] "Devis Contarato, Piero Giubilato" // [Version] "0.1" // [Modified by] "Devis Contarato" // [Last revision] "27 Aug 2008" // [Language] "C++" // [Compiler] "Visual C++ 8.x 9.x" // [Member of] "Cool SEAL" // [Project] "SEAL" // [Description] "Source for the gui_Text class" // [Key documentation] // "Visual C++ Reference Help" // "Root reference guide" // {Trace} //______________________________________________________________________________ // Standard component // Root Component #include // Application component #include "global.h" #include "gui_Text.h" // CINT Preprocessor class import definition ClassImp(gui_Text) //______________________________________________________________________________ gui_Text::gui_Text(TString entry, UInt_t left, UInt_t top, UInt_t width, UInt_t height) { // Default constructor. gui_Text provides an interface layer that // integrates a root TGTextEntry plus all the code necesary to implement // events management. // // 'entry' is the text appearing into the widget // 'left', 'top', 'width', 'height' set the position and size of the widget // '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_Text::gui_Text:(default)", DBG_LVL_ZERO); // Sets up the button Init(entry, left, top, width, height); } //______________________________________________________________________________ gui_Text::~gui_Text() { // Default destructor. dbg_Print("gui_Text::gui_Text:()", DBG_LVL_ZERO); // Removes the root object from the root graphical server Container()->RemoveFrame(textentry); textentry->DestroyWindow(); // Deletes the root object delete textentry; } //______________________________________________________________________________ void gui_Text::Init(TString entry, UInt_t left, UInt_t top, UInt_t width, UInt_t height) { // Creates a layer over a root text control dbg_Print("gui_Text::txt_Place:(default)", DBG_LVL_MAKE); // Initializes the root widget textentry = new TGTextEntry(Container(), entry); // Connects it to the widget handler function textentry->Connect(textentry, "ReturnPressed()", "gui_Text", this, "txt_Do(Long_t)"); // Renders the widget into the frame and adds it to the window Container()->AddFrame(textentry, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0)); MoveResize(left, top, width, height); // Also updates the container } //______________________________________________________________________________ void gui_Text::txt_Do(const char* txt) { // This function is called whenever the widget is used, as it has been // linked to the associated root TGTextButton when it was instantiated. dbg_Print("gui_Text::txt_Do:()", DBG_LVL_FLOW) // Calls the associated handler, if anyone, passing the ID as argument gui_Object::task_Call(gui_Object::obj_Id()); } //______________________________________________________________________________ const TGTextEntry* gui_Text::Root() const { // Returns the pointer to the embedded root object return textentry; } //______________________________________________________________________________ void gui_Text::MoveResize(UInt_t left, UInt_t top, UInt_t width, UInt_t height) { // Moves and resizes the widget textentry->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_Text::color_Set(UInt_t foreColor, UInt_t backColor) { // Moves and resizes the button textentry->SetForegroundColor(foreColor); textentry->SetBackgroundColor(backColor); // Stores the new datas obj_foreColor = foreColor; obj_backColor = backColor; // Refresh the graphical container Update(); } //______________________________________________________________________________ void gui_Text::Text(const char* text) { // Stores the new data obj_Text.Form(text); } //______________________________________________________________________________ const TString gui_Text::Text() const { // Returns the button text return obj_Text; } //______________________________________________________________________________ void gui_Text::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(); // No font bold at the moment for numeric // Sets the font into the button //text->SetFont(ft, false); // Stores the new data obj_fontBold = bold; // Refresh the graphical container Update(); } //______________________________________________________________________________ bool gui_Text::fontBold() const { // Returns the boldness of the button text return obj_fontBold; } //______________________________________________________________________________ const char* gui_Text::txt_Val() const { // Returns the current text entry return textentry->GetText(); }