CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/Fireworks/Core/src/FWEnumParameterSetter.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FWEnumParameterSetter
00005 // 
00006 // Implementation:
00007 //     [Notes on implementation]
00008 //
00009 // Original Author:  matevz
00010 //         Created:  Fri Apr 30 15:17:33 CEST 2010
00011 // $Id: FWEnumParameterSetter.cc,v 1.6 2011/02/15 18:32:34 amraktad Exp $
00012 //
00013 
00014 // system include files
00015 
00016 // user include files
00017 #include "Fireworks/Core/interface/FWEnumParameterSetter.h"
00018 #include "TGComboBox.h"
00019 #include "TGLabel.h"
00020 
00021 //
00022 // constants, enums and typedefs
00023 //
00024 
00025 //
00026 // static data member definitions
00027 //
00028 
00029 //
00030 // constructors and destructor
00031 //
00032 FWEnumParameterSetter::FWEnumParameterSetter() :
00033    m_param(0),
00034    m_widget(0)
00035 {}
00036 
00037 // FWEnumParameterSetter::FWEnumParameterSetter(const FWEnumParameterSetter& rhs)
00038 // {
00039 //    // do actual copying here;
00040 // }
00041 
00042 FWEnumParameterSetter::~FWEnumParameterSetter()
00043 {}
00044 
00045 //
00046 // assignment operators
00047 //
00048 // const FWEnumParameterSetter& FWEnumParameterSetter::operator=(const FWEnumParameterSetter& rhs)
00049 // {
00050 //   //An exception safe implementation is
00051 //   FWEnumParameterSetter temp(rhs);
00052 //   swap(rhs);
00053 //
00054 //   return *this;
00055 // }
00056 
00057 //
00058 // member functions
00059 //
00060 
00061 void
00062 FWEnumParameterSetter::attach(FWParameterBase* iParam)
00063 {
00064    m_param = dynamic_cast<FWEnumParameter*>(iParam);
00065    assert(0!=m_param);
00066 }
00067 
00068 TGFrame*
00069 FWEnumParameterSetter::build(TGFrame* iParent, bool labelBack)
00070 {
00071    TGCompositeFrame *frame = new TGHorizontalFrame(iParent);
00072 
00073    m_widget = new TGComboBox(frame);
00074    std::map<Long_t, std::string>::const_iterator me = m_param->entryMap().begin();
00075    UInt_t max_len = 0;
00076    while (me != m_param->entryMap().end())
00077    {
00078       m_widget->AddEntry(me->second.c_str(), static_cast<Int_t>(me->first));
00079       if (me->second.length() > max_len) max_len = me->second.length();
00080       ++me;
00081    }
00082    m_widget->Resize(8*max_len + 20, 20);
00083    m_widget->Select(static_cast<Int_t>(m_param->value()), kFALSE);
00084 
00085    m_widget->Connect("Selected(Int_t)", "FWEnumParameterSetter", this, "doUpdate(Int_t)");
00086 
00087    // label
00088    TGLabel* label = new TGLabel(frame, m_param->name().c_str());
00089    if (labelBack)
00090    {
00091       frame->AddFrame(m_widget, new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 2,6,2,2));
00092       frame->AddFrame(label, new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 2, 4, 0, 0));
00093    }
00094    else
00095    {
00096       frame->AddFrame(label, new TGLayoutHints(kLHintsLeft|kLHintsCenterY) );
00097       frame->AddFrame(m_widget, new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 2,8,2,2));
00098    }
00099    return frame;
00100 }
00101 
00102 void
00103 FWEnumParameterSetter::doUpdate(Int_t id)
00104 {
00105    assert(0!=m_param);
00106    assert(0!=m_widget);
00107    m_param->set((Long_t) id);
00108    update();
00109 }
00110 
00111 void
00112 FWEnumParameterSetter::setEnabled(bool x)
00113 {
00114    m_widget->SetEnabled(x);
00115 }
00116 
00117 //
00118 // const member functions
00119 //
00120 
00121 //
00122 // static member functions
00123 //