]> 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, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxFULL_REPAINT_ON_RESIZE)
36                 {
37                         this->m_OriginalListWx = modelList;
38                         this->m_OriginalListWx->Reparent(this);
39                         this->m_OriginalListWx->Show(true);
40                         this->m_OriginalListWx->SetFunctorEnabled(false);
41
42                         this->m_CurrentListWx = currentList;
43                         this->m_CurrentListWx->Reparent(this);
44                         this->m_CurrentListWx->SetFunctorEnabled(false);
45                         this->m_CurrentListWx->Show(true);
46                         this->m_LastStatus = this->m_CurrentListWx->GetListBox()->GetStrings();
47
48                         wxGridBagSizer* dialogSizer = new wxGridBagSizer(0, 0);
49                         dialogSizer->AddGrowableCol(0);
50                         dialogSizer->AddGrowableRow(0);
51
52                         //Top Sizer
53                         wxGridBagSizer* topSizer = new wxGridBagSizer(0, 0);
54                         topSizer->AddGrowableCol(0);
55                         topSizer->AddGrowableCol(2);
56                         topSizer->AddGrowableRow(0);
57                         topSizer->Add(this->m_OriginalListWx, wxGBPosition(0, 0), wxDefaultSpan,
58                                         wxALL | wxEXPAND | wxALIGN_CENTER_HORIZONTAL
59                                                         | wxALIGN_CENTER_VERTICAL, 5);
60                         wxBoxSizer* boxSizer1 = new wxBoxSizer(wxVERTICAL);
61                         this->m_AddButton = new wxBitmapButton(this, 1, wxNullBitmap,
62                                         wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW, wxDefaultValidator,
63                                         _T(">"));
64                         boxSizer1->Add(this->m_AddButton, 1,
65                                         wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 5);
66                         this->m_RemoveButton = new wxBitmapButton(this, 2, wxNullBitmap,
67                                         wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW, wxDefaultValidator,
68                                         _T("<"));
69                         boxSizer1->Add(this->m_RemoveButton, 1,
70                                         wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 5);
71                         topSizer->Add(boxSizer1, wxGBPosition(0, 1), wxDefaultSpan,
72                                         wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 5);
73
74                         topSizer->Add(this->m_CurrentListWx, wxGBPosition(0, 2), wxDefaultSpan,
75                                         wxALL | wxEXPAND | wxALIGN_CENTER_HORIZONTAL
76                                                         | wxALIGN_CENTER_VERTICAL, 5);
77                         wxBoxSizer* boxSizer2 = new wxBoxSizer(wxVERTICAL);
78                         this->m_UpButton = new wxBitmapButton(this, 3, wxNullBitmap,
79                                         wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW, wxDefaultValidator,
80                                         _T("+"));
81                         boxSizer2->Add(this->m_UpButton, 1,
82                                         wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 5);
83                         this->m_RemoveButton = new wxBitmapButton(this, 4, wxNullBitmap,
84                                         wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW, wxDefaultValidator,
85                                         _T("-"));
86                         boxSizer2->Add(this->m_RemoveButton, 1,
87                                         wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 5);
88                         topSizer->Add(boxSizer2, wxGBPosition(0, 3), wxDefaultSpan,
89                                         wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 5);
90                         dialogSizer->Add(topSizer, wxGBPosition(0, 0), wxDefaultSpan,
91                                         wxALL | wxEXPAND | wxALIGN_CENTER_HORIZONTAL
92                                                         | wxALIGN_CENTER_VERTICAL, 5);
93
94                         //Bottom Sizer
95
96                         wxBoxSizer* bottomSizer = new wxBoxSizer(wxHORIZONTAL);
97                         bottomSizer->Add(0, 0, 1,
98                                         wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 5);
99                         this->m_CancelButton = new wxButton(this, 5, _("Cancel"),
100                                         wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator,
101                                         _T("Cancel"));
102                         bottomSizer->Add(this->m_CancelButton, 1,
103                                         wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 5);
104                         this->m_OkButton = new wxButton(this, 6, _("Ok"), wxDefaultPosition,
105                                         wxDefaultSize, 0, wxDefaultValidator, _T("Ok"));
106                         bottomSizer->Add(this->m_OkButton, 1,
107                                         wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 5);
108                         bottomSizer->Add(0, 0, 1,
109                                         wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 5);
110                         dialogSizer->Add(bottomSizer, wxGBPosition(1, 0), wxDefaultSpan,
111                                         wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 5);
112                         this->SetSizer(dialogSizer);
113                         dialogSizer->Fit(this);
114                         dialogSizer->SetSizeHints(this);
115
116
117                         //---------------------------------------------------------------------------------------------
118                         // Events
119                         //Add
120                         Connect(1, wxEVT_COMMAND_BUTTON_CLICKED,
121                                         (wxObjectEventFunction) &ListConfigDialog::OnAdd);
122
123                         //Remove
124                         Connect(2, wxEVT_COMMAND_BUTTON_CLICKED,
125                                         (wxObjectEventFunction) &ListConfigDialog::OnDelete);
126
127                         //Up
128                         Connect(3, wxEVT_COMMAND_BUTTON_CLICKED,
129                                         (wxObjectEventFunction) &ListConfigDialog::OnMoveUp);
130
131                         //Down
132                         Connect(4, wxEVT_COMMAND_BUTTON_CLICKED,
133                                         (wxObjectEventFunction) &ListConfigDialog::OnMoveDown);
134
135                         //Cancel
136                         Connect(5, wxEVT_COMMAND_BUTTON_CLICKED,
137                                         (wxObjectEventFunction) &ListConfigDialog::OnCancel);
138
139                         //Ok
140                         Connect(6, wxEVT_COMMAND_BUTTON_CLICKED,
141                                         (wxObjectEventFunction) &ListConfigDialog::OnOk);
142
143                 }
144
145                 ListConfigDialog::~ListConfigDialog()
146                 {
147
148                 }
149
150                 void ListConfigDialog::OnAdd(wxCommandEvent& event)
151                 {
152                         wxString itSelect = m_OriginalListWx->GetListBox()->GetStringSelection();
153                         std::cout << "Count = " << this->m_CurrentListWx->GetListBox()->GetCount()
154                                         << std::endl;
155                         if (!itSelect.IsEmpty())
156                         {
157                                 int v = this->m_CurrentListWx->GetListBox()->FindString(itSelect);
158                                 if (v == -1)
159                                 {
160                                         this->m_CurrentListWx->GetListBox()->Append(itSelect);
161                                         this->m_CurrentListWx->GetListBox()->Update();
162                                 }
163                         }
164
165                 }
166                 void ListConfigDialog::OnDelete(wxCommandEvent& event)
167                 {
168                         wxString itSelect = m_CurrentListWx->GetListBox()->GetStringSelection();
169
170                         if (!itSelect.IsEmpty())
171                         {
172                                 int v = this->m_CurrentListWx->GetListBox()->FindString(itSelect);
173                                 if (v != -1)
174                                 {
175                                         this->m_CurrentListWx->GetListBox()->Delete(v);
176                                         this->m_CurrentListWx->GetListBox()->Update();
177                                 }
178                         }
179                 }
180                 void ListConfigDialog::OnMoveUp(wxCommandEvent& event)
181                 {
182                         wxString itSelect = m_CurrentListWx->GetListBox()->GetStringSelection();
183
184                         if (!itSelect.IsEmpty())
185                         {
186                                 int v = this->m_CurrentListWx->GetListBox()->FindString(itSelect);
187                                 if (v > 0)
188                                 {
189                                         this->m_CurrentListWx->GetListBox()->Delete(v);
190                                         this->m_CurrentListWx->GetListBox()->Insert(itSelect, v - 1);
191                                         this->m_CurrentListWx->GetListBox()->Update();
192                                 }
193                         }
194
195                 }
196                 void ListConfigDialog::OnMoveDown(wxCommandEvent& event)
197                 {
198                         wxString itSelect = m_CurrentListWx->GetListBox()->GetStringSelection();
199
200                         if (!itSelect.IsEmpty())
201                         {
202                                 int v = this->m_CurrentListWx->GetListBox()->FindString(itSelect);
203                                 std::cout << "Count = "
204                                                 << this->m_CurrentListWx->GetListBox()->GetCount() << std::endl;
205                                 if ((v < this->m_CurrentListWx->GetListBox()->GetCount() - 1)
206                                                 && (v != -1))
207                                 {
208                                         this->m_CurrentListWx->GetListBox()->Delete(v);
209                                         this->m_CurrentListWx->GetListBox()->Insert(itSelect, v + 1);
210                                         this->m_CurrentListWx->GetListBox()->Update();
211                                 }
212                         }
213
214                 }
215                 void ListConfigDialog::OnOk(wxCommandEvent& event)
216                 {
217
218                         this->EndModal(1);
219                 }
220                 void ListConfigDialog::OnCancel(wxCommandEvent& event)
221                 {
222
223                         this->m_CurrentListWx->GetListBox()->Clear();
224                         this->m_CurrentListWx->GetListBox()->Append(this->m_LastStatus);
225                         this->Close();
226                 }
227         }
228 }