//------------------------------------------------------------------------------ // gui combo boxes control class -- // (C) Piero Giubilato, Devis Contarato 2008-2010, Berkeley Lab -- //------------------------------------------------------------------------------ //______________________________________________________________________________ // {Trace} // [File name] "gui_Combo.cpp" // [Author] "Devis Contarato, Piero Giubilato" // [Version] "0.6" // [Modified by] "Devis Contarato" // [Last revision] "11 Feb 2009" // [Language] "C++" // [Compiler] "Visual C++ 8.x 9.x" // [Member of] "Cool SEAL" // [Project] "SEAL" // [Description] "Source for the gui_Combo class" // [Key documentation] // "Visual C++ Reference Help" // "Root reference guide" // {Trace} //______________________________________________________________________________ // Standard component // Root Component #include // Application component #include "global.h" #include "gui_Combo.h" // CINT Preprocessor class import definition ClassImp(gui_Combo) //______________________________________________________________________________ gui_Combo::gui_Combo(Int_t box_Id, UInt_t left, UInt_t top, UInt_t width, UInt_t height) { // Default constructor. gui_Combo provides an interface layer that // integrates a root TGComboBox plus all the code necesary to implement // events management. // // 'box_Id' is the combo box ID number // '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_Combo::gui_Combo:()", DBG_LVL_ZERO); // Sets up the widget Init(box_Id, left, top, width, height); } //______________________________________________________________________________ gui_Combo::~gui_Combo() { // Default destructor. dbg_Print("gui_Combo::gui_Combo:()", DBG_LVL_ZERO); // Removes the root object from the root graphical server Container()->RemoveFrame(combo); combo->DestroyWindow(); // Deletes the root object delete combo; } //______________________________________________________________________________ void gui_Combo::Init(Int_t box_Id, UInt_t left, UInt_t top, UInt_t width, UInt_t height) { // Creates a layer over a root combo box control dbg_Print("gui_Combo::Init:(default)", DBG_LVL_MAKE); // Initializes the root widget combo = new TGComboBox(Container(), box_Id); // Connects it to the widget handler function combo->Connect(combo, "Selected(Int_t)", "gui_Combo", this, "cbox_Do(Int_t)"); // Renders the widget into the frame and adds it to the window Container()->AddFrame(combo, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0)); MoveResize(left, top, width, height); // Also updates the container } //______________________________________________________________________________ void gui_Combo::cbox_Entry(const char* entry, Int_t entry_Id) { // Wrapper for the TGComboBox::AddEntry(const char* s, Int_t id) method dbg_Print("gui_Combo::cbox_Entry:()", DBG_LVL_FLOW); // Add an entry to the combo box combo->AddEntry(entry, entry_Id); // Update Update(); } //______________________________________________________________________________ const Int_t gui_Combo::cbox_Val() const { // Returns the id of the selected entry return combo->GetSelected(); } //______________________________________________________________________________ void gui_Combo::cbox_Val(Int_t val) { // Sets the id of the selected entry combo->Select(val); } //______________________________________________________________________________ void gui_Combo::cbox_Do(const Int_t box_Id) { // This function is called whenever the widget is used, as it has been // linked to the associated root TGComboBox when it was instantiated. dbg_Print("gui_Combo::cbox_Do:()", DBG_LVL_FLOW) // Calls the associated handler, if anyone, passing the ID as argument gui_Object::task_Call(gui_Object::obj_Id()); } //______________________________________________________________________________ TGComboBox* gui_Combo::Root() const { // Returns the pointer to the embedded root object return combo; } //______________________________________________________________________________ void gui_Combo::MoveResize(UInt_t left, UInt_t top, UInt_t width, UInt_t height) { // Moves and resizes the widget combo->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_Combo::color_Set(UInt_t foreColor, UInt_t backColor) { // Moves and resizes the button combo->SetForegroundColor(foreColor); combo->SetBackgroundColor(backColor); // Stores the new datas obj_foreColor = foreColor; obj_backColor = backColor; // Refresh the graphical container Update(); } //______________________________________________________________________________ void gui_Combo::Text(const char* text) { // Sets the button caption // At the monent, no text displayed into combo //combo->SetText(text); // Stores the new data obj_Text.Form(text); } //______________________________________________________________________________ const TString gui_Combo::Text() const { // Returns the widget text return obj_Text; } //______________________________________________________________________________ void gui_Combo::fontBold(bool bold) { // Sets the boldness of the widget 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 combo // Sets the font into the button //combo->SetFont(ft, false); // Stores the new data obj_fontBold = bold; // Refresh the graphical container Update(); } //______________________________________________________________________________ bool gui_Combo::fontBold() const { // Returns the boldness of the button text return obj_fontBold; }