]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/creaButtonContainer/view/listWx.cxx
32d101deac3b937e106529a7aa81183689b8770d
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / creaButtonContainer / view / listWx.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26
27
28 #include "listWx.h"
29
30 namespace creaButtonContainer
31 {
32         namespace view
33         {
34
35                 ListWx::ListWx( wxWindow* parent, wxWindowID id,ItemsMap iMap , TFunctor* functor ):
36                                 wxPanel(parent,id)
37                 {
38
39                         std::cout<< "MLER | ListWx::ListWx()" << std::endl;
40                         this->m_itemsMap = iMap;
41
42                         this->functor = functor;
43
44                         wxFlexGridSizer* sizer = new wxFlexGridSizer(1);
45                         sizer->Add( new  wxStaticText(this,-1, _("Lista")));
46                         sizer->AddGrowableCol(0);
47                         this->SetSizer(sizer);
48
49                         listBox = new wxListBox(this,-1);
50                         m_functorEnabled = true;
51
52                         std::cout << "is ListBox"<< listBox->GetId()<< std::endl;
53                 //      this->Connect( -1,wxEVT_COMMAND_CHOICE_SELECTED,
54                         //              (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))(&ListWx::ListEvent) );
55                         //this->Connect(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED,
56                                 //      wxCommandEventHandler(ListWx::ListEvent));
57
58                         this->Connect(wxEVT_COMMAND_LISTBOX_SELECTED,
59                                                  wxCommandEventHandler(ListWx::ListEvent));
60
61                         //FillList(0);
62
63
64                         sizer->Add(listBox,1,wxGROW);
65
66
67                 }
68
69                 // ----------------------------------------------------------------------------------
70
71                 ListWx::ListWx( wxWindow* parent, wxWindowID id, ItemsMap iMap,TFunctor* functor,
72                                 std::string c) : wxPanel(parent,id)
73                 {
74                         std::cout<< "MLER | ListWx::ListWx" << std::endl;
75
76                         this->m_itemsMap = iMap;
77                         this->functor = functor;
78
79                         wxFlexGridSizer* sizer = new wxFlexGridSizer(1);
80
81                         sizer->Add( new  wxStaticText(this,-1, _("Lista Configurable")));
82                         sizer->AddGrowableCol(0);
83                         this->SetSizer(sizer);
84
85                         listBox = new wxListBox(this,-1);
86
87                         std::cout << "is ListBox"<< listBox->GetId()<< std::endl;
88
89                         button = new wxButton(this, 1, _("Configurar"),
90                                         wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, wxString(c.c_str(), wxConvUTF8));
91
92                         sizer->Add(listBox,1,wxGROW);
93                         sizer->Add(button,2,wxGROW);
94
95                 //      m_listConfigPanel = new ListConfigPanel(this,1,_("Configuracion"),m_itemsMap);
96                         m_listConfig = new ListConfig(m_itemsMap);
97
98                         //wxEVT_COMMAND_LISTBOX_SELECTED
99                         this->Connect(wxEVT_COMMAND_LISTBOX_SELECTED,
100                                                 wxCommandEventHandler(ListWx::ListEvent));
101
102                         //FillList();
103
104                 }
105
106                 // ----------------------------------------------------------------------------------
107
108                 ListWx::~ListWx( )
109                 {
110                 }
111                 // ----------------------------------------------------------------------------------
112
113                 void
114                 ListWx::FillList()
115                 {
116                         this->listBox->Clear();
117                         std::cout<<"clear"<<std::endl;
118                         for (ItemsMap::iterator it=this->m_itemsMap.begin(); it!=this->m_itemsMap.end(); ++it)
119                         {
120                                 std::string key = it->first;
121                                 int v = listBox->FindString(wxString(key.c_str(), wxConvUTF8));
122                                 if(v == -1)
123                                         listBox->Append( wxString(key.c_str(), wxConvUTF8));
124                         }
125                         listBox->Update();
126                         this->Update();
127                 }
128                 // ----------------------------------------------------------------------------------
129
130                 void
131                 ListWx::ListEvent( wxCommandEvent& event )
132                 {
133                         if(!this->IsFunctorEnabled())
134                                 return;
135                         else{
136                         try
137                         {
138                                 std::cout<< "MLER | ListWx::ListEvent( wxListEvent& event )" << std::endl;
139
140                                 int iSelection;
141                                 iSelection = listBox->GetSelection();
142
143                                 wxString itemNom = listBox->GetString(iSelection);
144                                 std::string itemNomC = std::string(itemNom.mb_str());
145
146                                 this->functor->Call(itemNomC);
147                                 std::cout<<"mmmmmmmmmmmmmmmmmmmmmmm"<<std::endl;
148
149
150                         }//yrt
151                         catch ( const std::exception& e )
152                         {
153                                 std::cerr
154                                     << "ButtonContainerController::ButtonEvent( wxCommandEvent& event ) exception: "
155                                     << e.what( ) << std::endl;
156                         }//hctac
157                         }
158                 }
159                 // ----------------------------------------------------------------------------------
160
161
162
163                 ListWx::ItemsMap
164                 ListWx::GetItemsMap()
165                 {
166                         return m_itemsMap;
167                 }
168
169                 void ListWx::SetFunctorEnabled(const bool& enabled)
170                 {
171                         m_functorEnabled = enabled;
172                 }
173
174                 bool ListWx::IsFunctorEnabled() const
175                 {
176                         return m_functorEnabled;
177                 }
178
179                 ListWx::TFunctor*
180                 ListWx::GetWxListFunctor()
181                 {
182                         return this->functor;
183                 }
184
185                 void ListWx::AddItemToMap(std::string key, wxPanel* panel)
186                 {
187                         this->m_itemsMap[key] = panel;
188                 }
189
190                 wxListBox*
191                 ListWx::GetListBox() const
192                 {
193                         return this->listBox;
194                 }
195
196
197                 void ListWx::DeleteItemFromMap(std::string key)
198                 {
199                         std::cout<< "MLER | ListConfig::DelFinalItems(std::string name)" << std::endl;
200                         ItemsMap::iterator it1;
201
202                         //if(m_finalItems.empty())
203                         std::cout<<"name item -----test A"<< key <<std::endl;
204                         if(!this->m_itemsMap.empty())
205                         {
206                                 for(ItemsMap::iterator it= this->m_itemsMap.begin(); it!=this->m_itemsMap.end();++it)
207                                 {
208                                         if((it->first).compare(key) == 0  )
209                                         {
210                                                 std::cout << "Item a borrar: "<< key << std::endl;
211                                                 it1 = m_itemsMap.find(key);
212                                                 m_itemsMap.erase(it1);
213
214                                         }
215                                 }
216                         }
217                                         std::cout<< "si borre tengo --- test 2 "<< m_itemsMap.size() << std::endl;
218                 }
219
220
221         }//ecapseman
222 }//ecapseman
223
224