]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/creaButtonContainer/controller/buttonContainerController.cxx
f6369523738b99348273e11bcad529202937e78d
[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
50                 ButtonContainerController::AddEvents( )
51                 {
52                         try
53                         {
54                                 //Adding ButtonManagerEvents
55                                 for( GroupManagerList::iterator it =
56                                     this->m_BCPanel->m_GroupManagerList.begin( ); it
57                                     != this->m_BCPanel->m_GroupManagerList.end( ); ++it )
58                                 {
59                                         this->Connect(
60                                             ( *it ).first,
61                                             wxEVT_COMMAND_BUTTON_CLICKED,
62                                             (wxObjectEventFunction) &ButtonContainerController::ButtonExpEvent );
63                                 }//rof
64
65                                 //Adding ButtonEvents
66                                 for( ButtonGroupList::iterator it =
67                                     this->m_BCPanel->m_ButtonGroupList.begin( ); it
68                                     != this->m_BCPanel->m_ButtonGroupList.end( ); ++it )
69                                 {
70                                         KeyList keylist = ( *it )->GetButtonIdContainer( );
71                                         for( KeyList::iterator it2 = keylist.begin( ); it2 != keylist.end( ); ++it2 )
72                                         {
73                                                 this->Connect( ( *it2 ), wxEVT_COMMAND_BUTTON_CLICKED,
74                                                     (wxObjectEventFunction) &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
86                 ButtonContainerController::ButtonExpEvent( wxCommandEvent& event )
87                 {
88                         long id = event.GetId( );
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
117                 ButtonContainerController::ButtonEvent( wxCommandEvent& event )
118                 {
119                         try
120                         {
121                                 for( ButtonGroupList::iterator it =
122                                     this->m_BCPanel->m_ButtonGroupList.begin( ); it
123                                     != this->m_BCPanel->m_ButtonGroupList.end( ); ++it )
124                                 {
125                                         if ( ( *it )->GetButton( event.GetId( ) ) != NULL )
126                                         {
127                                                 ( *it )->GetButton( event.GetId( ) )->Execute( );
128                                         }//fi
129                                 }//rof
130                         }//yrt
131                         catch ( const std::exception& e )
132                         {
133                                 std::cerr
134                                     << "ButtonContainerController::ButtonEvent( wxCommandEvent& event ) exception: "
135                                     << e.what( ) << std::endl;
136                         }//hctac
137                 }
138         // ----------------------------------------------------------------------------------
139         }//ecapsename
140 }//ecapsename
141