]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/creaButtonContainer/view/listWx.cxx
c7cfc56aa189a9aa2b9c5160372542351099224b
[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
51                         std::cout << "is ListBox"<< listBox->GetId()<< std::endl;
52                 //      this->Connect( -1,wxEVT_COMMAND_CHOICE_SELECTED,
53                         //              (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))(&ListWx::ListEvent) );
54                         //this->Connect(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED,
55                                 //      wxCommandEventHandler(ListWx::ListEvent));
56
57                         this->Connect(wxEVT_COMMAND_LISTBOX_SELECTED,
58                                                  wxCommandEventHandler(ListWx::ListEvent));
59
60                         //FillList(0);
61
62
63                         sizer->Add(listBox,1,wxGROW);
64
65
66                 }
67
68                 // ----------------------------------------------------------------------------------
69
70                 ListWx::ListWx( wxWindow* parent, wxWindowID id, ItemsMap iMap,TFunctor* functor,
71                                 std::string c) : wxPanel(parent,id)
72                 {
73                         std::cout<< "MLER | ListWx::ListWx" << std::endl;
74
75                         this->m_itemsMap = iMap;
76                         this->functor = functor;
77
78                         wxFlexGridSizer* sizer = new wxFlexGridSizer(1);
79
80                         sizer->Add( new  wxStaticText(this,-1, _("Lista Configurable")));
81                         sizer->AddGrowableCol(0);
82                         this->SetSizer(sizer);
83
84                         listBox = new wxListBox(this,-1);
85
86                         std::cout << "is ListBox"<< listBox->GetId()<< std::endl;
87
88                         button = new wxButton(this, 1, _("Configurar"),
89                                         wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, wxString(c.c_str(), wxConvUTF8));
90
91                         sizer->Add(listBox,1,wxGROW);
92                         sizer->Add(button,2,wxGROW);
93
94                 //      m_listConfigPanel = new ListConfigPanel(this,1,_("Configuracion"),m_itemsMap);
95                         m_listConfig = new ListConfig(m_itemsMap);
96
97                         //wxEVT_COMMAND_LISTBOX_SELECTED
98                         this->Connect(wxEVT_COMMAND_LISTBOX_SELECTED,
99                                                 wxCommandEventHandler(ListWx::ListEvent));
100
101                         //FillList();
102
103                 }
104
105                 // ----------------------------------------------------------------------------------
106
107                 ListWx::~ListWx( )
108                 {
109                 }
110                 // ----------------------------------------------------------------------------------
111
112                 void
113                 ListWx::FillList()
114                 {
115                         this->listBox->Clear();
116                         std::cout<<"clear"<<std::endl;
117                         for (ItemsMap::iterator it=this->m_itemsMap.begin(); it!=this->m_itemsMap.end(); ++it)
118                         {
119                                 std::string key = it->first;
120                                 int v = listBox->FindString(wxString(key.c_str(), wxConvUTF8));
121                                 if(v == -1)
122                                         listBox->Append( wxString(key.c_str(), wxConvUTF8));
123                         }
124                         listBox->Update();
125                         this->Update();
126                 }
127                 // ----------------------------------------------------------------------------------
128
129                 void
130                 ListWx::ListEvent( wxCommandEvent& event )
131                 {
132                         if(!this->IsFunctorEnabled())
133                                 return;
134                         try
135                         {
136                                 std::cout<< "MLER | ListWx::ListEvent( wxListEvent& event )" << std::endl;
137
138                         //      wxString itemNom = this->GetString(this->GetSelection());
139
140                         //      std::string itemNomC = std::string(itemNom.mb_str());
141
142                                 //this->functor->Call(itemNomC);
143
144                                 int iSelection;
145                                 iSelection = listBox->GetSelection();
146
147                                 wxString itemNom = listBox->GetString(iSelection);
148                                 std::string itemNomC = std::string(itemNom.mb_str());
149
150                                 this->functor->Call(itemNomC);
151                                 std::cout<<"mmmmmmmmmmmmmmmmmmmmmmm"<<std::endl;
152
153
154                         }//yrt
155                         catch ( const std::exception& e )
156                         {
157                                 std::cerr
158                                     << "ButtonContainerController::ButtonEvent( wxCommandEvent& event ) exception: "
159                                     << e.what( ) << std::endl;
160                         }//hctac
161                 }
162                 // ----------------------------------------------------------------------------------
163
164
165
166                 ListWx::ItemsMap
167                 ListWx::GetItemsMap()
168                 {
169                         return m_itemsMap;
170                 }
171
172                 void ListWx::SetFunctorEnabled(const bool& enabled)
173                 {
174                         m_functorEnabled = enabled;
175                 }
176
177                 bool ListWx::IsFunctorEnabled() const
178                 {
179                         return m_functorEnabled;
180                 }
181
182                 ListWx::TFunctor*
183                 ListWx::GetWxListFunctor()
184                 {
185                         return this->functor;
186                 }
187
188                 void ListWx::AddItemToMap(std::string key, wxPanel* panel)
189                 {
190                         this->m_itemsMap[key] = panel;
191                 }
192
193                 wxListBox*
194                 ListWx::GetListBox() const
195                 {
196                         return this->listBox;
197                 }
198
199
200                 void ListWx::DeleteItemFromMap(std::string key)
201                 {
202                         std::cout<< "MLER | ListConfig::DelFinalItems(std::string name)" << std::endl;
203                         ItemsMap::iterator it1;
204
205                         //if(m_finalItems.empty())
206                         std::cout<<"name item -----test A"<< key <<std::endl;
207                         if(!this->m_itemsMap.empty())
208                         {
209                                 for(ItemsMap::iterator it= this->m_itemsMap.begin(); it!=this->m_itemsMap.end();++it)
210                                 {
211                                         if((it->first).compare(key) == 0  )
212                                         {
213                                                 std::cout << "Item a borrar: "<< key << std::endl;
214                                                 it1 = m_itemsMap.find(key);
215                                                 m_itemsMap.erase(it1);
216
217                                         }
218                                 }
219                         }
220                                         std::cout<< "si borre tengo --- test 2 "<< m_itemsMap.size() << std::endl;
221                 }
222
223
224         }//ecapseman
225 }//ecapseman
226
227