]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/creaButtonContainer/controller/buttonContainerController.cxx
Code cleaning done
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / creaButtonContainer / controller / buttonContainerController.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  * @file buttonContainerController.cxx
28  * @brief This contains the ButtonContainerController class implementation
29  * @author Diego CACERES (diego.caceres[AT]creatis.insa-lyon.fr)
30  * @date  2011-06-02
31  */
32
33 #include "buttonContainerController.h"
34
35 namespace creaButtonContainer
36 {
37         namespace controller
38         {
39                 // ----------------------------------------------------------------------------------
40                 ButtonContainerController::ButtonContainerController(BCPanel* panel)
41                 {
42                         this->m_BCPanel = panel;
43                 }
44                 // ----------------------------------------------------------------------------------
45                 ButtonContainerController::~ButtonContainerController()
46                 {
47                 }
48                 // ----------------------------------------------------------------------------------
49                 void ButtonContainerController::AddEvents()
50                 {
51                         try
52                         {
53                                 //Adding ButtonManagerEvents
54                                 for (GroupManagerList::iterator it =
55                                                 this->m_BCPanel->m_GroupManagerList.begin();
56                                                 it != this->m_BCPanel->m_GroupManagerList.end(); ++it)
57                                 {
58                                         this->Connect((*it).first, wxEVT_COMMAND_BUTTON_CLICKED,
59                                                         (wxObjectEventFunction)
60                                                                         & ButtonContainerController::ButtonExpEvent);
61                                 } //rof
62
63                                 //Adding ButtonEvents
64                                 for (ButtonGroupList::iterator it =
65                                                 this->m_BCPanel->m_ButtonGroupList.begin();
66                                                 it != this->m_BCPanel->m_ButtonGroupList.end(); ++it)
67                                 {
68                                         KeyList keylist = (*it)->GetButtonIdContainer();
69                                         for (KeyList::iterator it2 = keylist.begin(); it2 != keylist.end();
70                                                         ++it2)
71                                         {
72                                                 this->Connect((*it2), wxEVT_COMMAND_BUTTON_CLICKED,
73                                                                 (wxObjectEventFunction)
74                                                                                 & ButtonContainerController::ButtonEvent);
75                                         } //rof
76                                 } //rof
77                         } //yrt
78                         catch (const std::exception& e)
79                         {
80                                 std::cerr << "ButtonContainerController::AddEvents( ) exception: "
81                                                 << e.what() << std::endl;
82                         } //hctac
83                 }
84                 // ----------------------------------------------------------------------------------
85                 void ButtonContainerController::ButtonExpEvent(wxCommandEvent& event)
86                 {
87                         long id = event.GetId();
88
89                         try
90                         {
91                                 //changing the button label when its clicked and then hide the buttons of the group.
92                                 if (this->m_BCPanel->m_GroupManagerList[id]->GetButton()->GetLabel().Cmp(
93                                                 _("+")) == 0)
94                                 {
95                                         this->m_BCPanel->m_GroupManagerList[id]->GetButton()->SetLabel(
96                                                         _("-"));
97                                         this->m_BCPanel->m_GroupManagerList[id]->HideSubPanel(false);
98                                 } //fi
99                                 else if (this->m_BCPanel->m_GroupManagerList[id]->GetButton()->GetLabel().Cmp(
100                                                 _("-")) == 0)
101                                 {
102                                         this->m_BCPanel->m_GroupManagerList[id]->GetButton()->SetLabel(
103                                                         _("+"));
104                                         this->m_BCPanel->m_GroupManagerList[id]->HideSubPanel(true);
105                                 } //fi esle
106                                 this->m_BCPanel->FitSizer();
107                         } //yrt
108                         catch (const std::exception& e)
109                         {
110                                 std::cerr
111                                                 << "ButtonContainerController::ButtonExpEvent( wxCommandEvent& event ) exception: "
112                                                 << e.what() << std::endl;
113                         } //hctac
114                 }
115                 // ----------------------------------------------------------------------------------
116                 void ButtonContainerController::ButtonEvent(wxCommandEvent& event)
117                 {
118                         try
119                         {
120                                 for (ButtonGroupList::iterator it =
121                                                 this->m_BCPanel->m_ButtonGroupList.begin();
122                                                 it != this->m_BCPanel->m_ButtonGroupList.end(); ++it)
123                                 {
124                                         if ((*it)->GetButton(event.GetId()) != NULL)
125                                         {
126                                                 (*it)->GetButton(event.GetId())->Execute();
127                                         } //fi
128                                 } //rof
129                         } //yrt
130                         catch (const std::exception& e)
131                         {
132                                 std::cerr
133                                                 << "ButtonContainerController::ButtonEvent( wxCommandEvent& event ) exception: "
134                                                 << e.what() << std::endl;
135                         } //hctac
136                 }
137         // ----------------------------------------------------------------------------------
138
139         }//ecapsename
140 } //ecapsename
141