CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/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.7 2012/09/21 09:26:26 eulisse 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 #include <cassert>
00021 
00022 //
00023 // constants, enums and typedefs
00024 //
00025 
00026 //
00027 // static data member definitions
00028 //
00029 
00030 //
00031 // constructors and destructor
00032 //
00033 FWEnumParameterSetter::FWEnumParameterSetter() :
00034    m_param(0),
00035    m_widget(0)
00036 {}
00037 
00038 // FWEnumParameterSetter::FWEnumParameterSetter(const FWEnumParameterSetter& rhs)
00039 // {
00040 //    // do actual copying here;
00041 // }
00042 
00043 FWEnumParameterSetter::~FWEnumParameterSetter()
00044 {}
00045 
00046 //
00047 // assignment operators
00048 //
00049 // const FWEnumParameterSetter& FWEnumParameterSetter::operator=(const FWEnumParameterSetter& rhs)
00050 // {
00051 //   //An exception safe implementation is
00052 //   FWEnumParameterSetter temp(rhs);
00053 //   swap(rhs);
00054 //
00055 //   return *this;
00056 // }
00057 
00058 //
00059 // member functions
00060 //
00061 
00062 void
00063 FWEnumParameterSetter::attach(FWParameterBase* iParam)
00064 {
00065    m_param = dynamic_cast<FWEnumParameter*>(iParam);
00066    assert(0!=m_param);
00067 }
00068 
00069 TGFrame*
00070 FWEnumParameterSetter::build(TGFrame* iParent, bool labelBack)
00071 {
00072    TGCompositeFrame *frame = new TGHorizontalFrame(iParent);
00073 
00074    m_widget = new TGComboBox(frame);
00075    std::map<Long_t, std::string>::const_iterator me = m_param->entryMap().begin();
00076    UInt_t max_len = 0;
00077    while (me != m_param->entryMap().end())
00078    {
00079       m_widget->AddEntry(me->second.c_str(), static_cast<Int_t>(me->first));
00080       if (me->second.length() > max_len) max_len = me->second.length();
00081       ++me;
00082    }
00083    m_widget->Resize(8*max_len + 20, 20);
00084    m_widget->Select(static_cast<Int_t>(m_param->value()), kFALSE);
00085 
00086    m_widget->Connect("Selected(Int_t)", "FWEnumParameterSetter", this, "doUpdate(Int_t)");
00087 
00088    // label
00089    TGLabel* label = new TGLabel(frame, m_param->name().c_str());
00090    if (labelBack)
00091    {
00092       frame->AddFrame(m_widget, new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 2,6,2,2));
00093       frame->AddFrame(label, new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 2, 4, 0, 0));
00094    }
00095    else
00096    {
00097       frame->AddFrame(label, new TGLayoutHints(kLHintsLeft|kLHintsCenterY) );
00098       frame->AddFrame(m_widget, new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 2,8,2,2));
00099    }
00100    return frame;
00101 }
00102 
00103 void
00104 FWEnumParameterSetter::doUpdate(Int_t id)
00105 {
00106    assert(0!=m_param);
00107    assert(0!=m_widget);
00108    m_param->set((Long_t) id);
00109    update();
00110 }
00111 
00112 void
00113 FWEnumParameterSetter::setEnabled(bool x)
00114 {
00115    m_widget->SetEnabled(x);
00116 }
00117 
00118 //
00119 // const member functions
00120 //
00121 
00122 //
00123 // static member functions
00124 //