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