]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/creaButtonContainer/view/listConfigDialog.cxx
#2516 creaMaracasVisu Feature New Normal - creaPanelButtonContainer ListPanel with...
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / creaButtonContainer / view / listConfigDialog.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 #include "listConfigDialog.h"
27
28 namespace creaButtonContainer
29 {
30
31         namespace view
32         {
33                 ListConfigDialog::ListConfigDialog(wxWindow* parent, wxWindowID id,
34                                 const wxString& title, ListWx* modelList, ListWx* currentList)
35                                 : wxDialog(parent, id, title)
36                 {
37                         std::cout << "MLER | ListConfigPanel::ListConfigPanel()" << std::endl;
38
39                         this->m_OriginalListWx = modelList;
40                         this->m_OriginalListWx->Reparent(this);
41                         this->m_OriginalListWx->Show(true);
42                         this->m_OriginalListWx->SetFunctorEnabled(false);
43                         //this->m_OriginalListWx->FillList();
44
45                         this->m_CurrentListWx = currentList;
46                         this->m_CurrentListWx->Reparent(this);
47                         this->m_CurrentListWx->SetFunctorEnabled(false);
48                         this->m_CurrentListWx->Show(true);
49                         //this->m_CurrentListWx->FillList();
50
51                         wxFlexGridSizer* sizer = new wxFlexGridSizer(2, 1, 0, 0);
52                         this->SetSizer(sizer);
53
54                         wxBoxSizer* sizerUp = new wxBoxSizer(wxHORIZONTAL);
55
56                         sizerUp->Add(this->m_OriginalListWx, 0, wxEXPAND);
57                         //========
58
59                         wxPanel* panel2 = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize,
60                                         wxTAB_TRAVERSAL, _T("Panel 2"));
61                         wxBoxSizer* sizerList2 = new wxBoxSizer(wxVERTICAL);
62
63                         buttonAdd = new wxButton(panel2, 1, _(">"), wxDefaultPosition,
64                                         wxDefaultSize, 0, wxDefaultValidator, _T("Add"));
65                         sizerList2->Add(buttonAdd, 0, wxEXPAND);
66
67                         buttonDel = new wxButton(panel2, 2, _("<"), wxDefaultPosition,
68                                         wxDefaultSize, 0, wxDefaultValidator, _T("Delete"));
69                         sizerList2->Add(buttonDel, 0, wxEXPAND);
70
71                         panel2->SetSizer(sizerList2);
72                         sizerList2->Fit(panel2);
73                         sizerList2->SetSizeHints(panel2);
74
75                         sizerUp->Add(panel2, 0, wxEXPAND);
76
77                         //========
78
79                         sizerUp->Add(this->m_CurrentListWx, 0, wxEXPAND);
80
81                         //=======
82                         wxPanel* panel5 = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize,
83                                         wxTAB_TRAVERSAL, _T("Panel 5"));
84                         wxBoxSizer* sizerList4 = new wxBoxSizer(wxVERTICAL);
85
86                         upButton = new wxButton(panel5, 3, _("/\\"), wxDefaultPosition,
87                                         wxDefaultSize, 0, wxDefaultValidator, _T("upButton"));
88                         sizerList4->Add(upButton, 0, wxEXPAND);
89
90                         downButton = new wxButton(panel5, 4, _("V"), wxDefaultPosition,
91                                         wxDefaultSize, 0, wxDefaultValidator, _T("downButton"));
92                         sizerList4->Add(downButton, 0, wxEXPAND);
93
94                         panel5->SetSizer(sizerList4);
95                         sizerList4->Fit(panel5);
96                         sizerList4->SetSizeHints(panel5);
97                         sizerUp->Add(panel5, 0, wxEXPAND);
98
99                         //========
100                         wxBoxSizer* sizerBotones = new wxBoxSizer(wxHORIZONTAL);
101                         wxPanel* panel4 = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize,
102                                         wxTAB_TRAVERSAL, _T("Panel 4"));
103
104                         okButton = new wxButton(panel4, 5, _("Ok"), wxPoint(0, 8), wxDefaultSize,
105                                         0, wxDefaultValidator, _T("Ok"));
106                         cancelButton = new wxButton(panel4, 6, _("Cancel"), wxPoint(88, 8),
107                                         wxDefaultSize, 0, wxDefaultValidator, _T("Cancel"));
108
109                         sizerBotones->Add(panel4, 0, wxEXPAND);
110
111                         sizer->Add(sizerUp, 0, wxEXPAND);
112                         sizer->Add(sizerBotones, 1, wxALL | wxALIGN_CENTER_HORIZONTAL);
113
114                         //---------------------------------------------------------------------------------------------
115                         // Manejo de Eventos
116
117                         //Evento Cancel
118                         Connect(6, wxEVT_COMMAND_BUTTON_CLICKED,
119                                         (wxObjectEventFunction) & ListConfigDialog::OnCancel);
120
121                         //EventoSeleccionarLista
122                         //Connect(wxEVT_COMMAND_LISTBOX_SELECTED,wxCommandEventHandler(ListConfigPanel::ListItemEvent));
123
124                         //EventoAdd
125                         Connect(1, wxEVT_COMMAND_BUTTON_CLICKED,
126                                         (wxObjectEventFunction) & ListConfigDialog::OnAdd);
127
128                         //EventoOk
129                         Connect(5, wxEVT_COMMAND_BUTTON_CLICKED,
130                                         (wxObjectEventFunction) & ListConfigDialog::OnOk);
131
132                         //EventoDelete
133                         Connect(2, wxEVT_COMMAND_BUTTON_CLICKED,
134                                         (wxObjectEventFunction) & ListConfigDialog::OnDelete);
135
136                         //EventoUp
137                         Connect(3, wxEVT_COMMAND_BUTTON_CLICKED,
138                                         (wxObjectEventFunction) & ListConfigDialog::OnMoveUp);
139
140                         //EventoUp
141                         Connect(4, wxEVT_COMMAND_BUTTON_CLICKED,
142                                         (wxObjectEventFunction) & ListConfigDialog::OnMoveDown);
143
144                 }
145
146                 ListConfigDialog::~ListConfigDialog()
147                 {
148
149                 }
150
151                 void ListConfigDialog::OnAdd(wxCommandEvent& event)
152                 {
153                         wxString itSelect = m_OriginalListWx->GetListBox()->GetStringSelection();
154                         int v;
155                         std::cout << "Count = " << this->m_CurrentListWx->GetListBox()->GetCount()
156                                         << std::endl;
157                         if (!itSelect.IsEmpty())
158                         {
159                                 int v = this->m_CurrentListWx->GetListBox()->FindString(itSelect);
160                                 if (v == -1)
161                                 {
162                                         this->m_CurrentListWx->GetListBox()->Append(itSelect);
163                                         this->m_CurrentListWx->GetListBox()->Update();
164                                 }
165                         }
166
167                 }
168                 void ListConfigDialog::OnDelete(wxCommandEvent& event)
169                 {
170                         wxString itSelect = m_CurrentListWx->GetListBox()->GetStringSelection();
171
172                         if (!itSelect.IsEmpty())
173                         {
174                                 int v = this->m_CurrentListWx->GetListBox()->FindString(itSelect);
175                                 if (v != -1)
176                                 {
177                                         this->m_CurrentListWx->GetListBox()->Delete(v);
178                                         this->m_CurrentListWx->GetListBox()->Update();
179                                 }
180                         }
181                 }
182                 void ListConfigDialog::OnMoveUp(wxCommandEvent& event)
183                 {
184                         wxString itSelect = m_CurrentListWx->GetListBox()->GetStringSelection();
185
186                         if (!itSelect.IsEmpty())
187                         {
188                                 int v = this->m_CurrentListWx->GetListBox()->FindString(itSelect);
189                                 if (v > 0)
190                                 {
191                                         this->m_CurrentListWx->GetListBox()->Delete(v);
192                                         this->m_CurrentListWx->GetListBox()->Insert(itSelect, v - 1);
193                                         this->m_CurrentListWx->GetListBox()->Update();
194                                 }
195                         }
196
197                 }
198                 void ListConfigDialog::OnMoveDown(wxCommandEvent& event)
199                 {
200                         wxString itSelect = m_CurrentListWx->GetListBox()->GetStringSelection();
201
202                         if (!itSelect.IsEmpty())
203                         {
204                                 int v = this->m_CurrentListWx->GetListBox()->FindString(itSelect);
205                                 std::cout << "Count = "
206                                                 << this->m_CurrentListWx->GetListBox()->GetCount() << std::endl;
207                                 if ((v < this->m_CurrentListWx->GetListBox()->GetCount() - 1)
208                                                 && (v != -1))
209                                 {
210                                         this->m_CurrentListWx->GetListBox()->Delete(v);
211                                         this->m_CurrentListWx->GetListBox()->Insert(itSelect, v + 1);
212                                         this->m_CurrentListWx->GetListBox()->Update();
213                                 }
214                         }
215
216                 }
217                 void ListConfigDialog::OnOk(wxCommandEvent& event)
218                 {
219                         this->EndModal(1);
220                 }
221                 void ListConfigDialog::OnCancel(wxCommandEvent& event)
222                 {
223                         Close();
224                 }
225         }
226 }