]> Creatis software - creaMaracasVisu.git/blob
7cba265abeefa6362d8f6106939e37e2391bff26
[creaMaracasVisu.git] /
1 /*!
2  * @file buttonContainerController.cxx
3  * @brief This contains the ButtonContainerController class implementation
4  * @author Diego CACERES (diego.caceres[AT]creatis.insa-lyon.fr)
5  * @date  2011-06-02
6  */
7
8 #include "buttonContainerController.h"
9
10 namespace creaButtonContainer
11 {
12         namespace controller
13         {
14                 // ----------------------------------------------------------------------------------
15                 ButtonContainerController::ButtonContainerController( BCPanel* panel )
16                 {
17                         this->m_BCPanel = panel;
18                 }
19                 // ----------------------------------------------------------------------------------
20                 ButtonContainerController::~ButtonContainerController( )
21                 {
22                 }
23                 // ----------------------------------------------------------------------------------
24                 void
25                 ButtonContainerController::AddEvents( )
26                 {
27                         try
28                         {
29                                 //Adding ButtonManagerEvents
30                                 for( GroupManagerList::iterator it =
31                                     this->m_BCPanel->m_GroupManagerList.begin( ); it
32                                     != this->m_BCPanel->m_GroupManagerList.end( ); ++it )
33                                 {
34                                         this->Connect(
35                                             ( *it ).first,
36                                             wxEVT_COMMAND_BUTTON_CLICKED,
37                                             (wxObjectEventFunction) &ButtonContainerController::ButtonExpEvent );
38                                 }//rof
39
40                                 //Adding ButtonEvents
41                                 for( ButtonGroupList::iterator it =
42                                     this->m_BCPanel->m_ButtonGroupList.begin( ); it
43                                     != this->m_BCPanel->m_ButtonGroupList.end( ); ++it )
44                                 {
45                                         KeyList keylist = ( *it )->GetButtonIdContainer( );
46                                         for( KeyList::iterator it2 = keylist.begin( ); it2 != keylist.end( ); ++it2 )
47                                         {
48                                                 this->Connect( ( *it2 ), wxEVT_COMMAND_BUTTON_CLICKED,
49                                                     (wxObjectEventFunction) &ButtonContainerController::ButtonEvent );
50                                         }//rof
51                                 }//rof
52                         }//yrt
53                         catch ( const std::exception& e )
54                         {
55                                 std::cerr << "ButtonContainerController::AddEvents( ) exception: "
56                                     << e.what( ) << std::endl;
57                         }//hctac
58                 }
59                 // ----------------------------------------------------------------------------------
60                 void
61                 ButtonContainerController::ButtonExpEvent( wxCommandEvent& event )
62                 {
63                         long id = event.GetId( );
64                         try
65                         {
66                                 //changing the button label when its clicked and then hide the buttons of the group.
67                                 if ( this->m_BCPanel->m_GroupManagerList[ id ]->GetButton( )->GetLabel( ).Cmp(
68                                     _( "+" ) ) == 0 )
69                                 {
70                                         this->m_BCPanel->m_GroupManagerList[ id ]->GetButton( )->SetLabel(
71                                             _( "-" ) );
72                                         this->m_BCPanel->m_GroupManagerList[ id ]->HideSubPanel( false );
73                                 }//fi
74                                 else if ( this->m_BCPanel->m_GroupManagerList[ id ]->GetButton( )->GetLabel( ).Cmp(
75                                     _( "-" ) ) == 0 )
76                                 {
77                                         this->m_BCPanel->m_GroupManagerList[ id ]->GetButton( )->SetLabel(
78                                             _( "+" ) );
79                                         this->m_BCPanel->m_GroupManagerList[ id ]->HideSubPanel( true );
80                                 }//fi esle
81                                 this->m_BCPanel->FitSizer( );
82                         }//yrt
83                         catch ( const std::exception& e )
84                         {
85                                 std::cerr
86                                     << "ButtonContainerController::ButtonExpEvent( wxCommandEvent& event ) exception: "
87                                     << e.what( ) << std::endl;
88                         }//hctac
89                 }
90                 // ----------------------------------------------------------------------------------
91                 void
92                 ButtonContainerController::ButtonEvent( wxCommandEvent& event )
93                 {
94                         try
95                         {
96                                 for( ButtonGroupList::iterator it =
97                                     this->m_BCPanel->m_ButtonGroupList.begin( ); it
98                                     != this->m_BCPanel->m_ButtonGroupList.end( ); ++it )
99                                 {
100                                         if ( ( *it )->GetButton( event.GetId( ) ) != NULL )
101                                         {
102                                                 ( *it )->GetButton( event.GetId( ) )->Execute( );
103                                         }//fi
104                                 }//rof
105                         }//yrt
106                         catch ( const std::exception& e )
107                         {
108                                 std::cerr
109                                     << "ButtonContainerController::ButtonEvent( wxCommandEvent& event ) exception: "
110                                     << e.what( ) << std::endl;
111                         }//hctac
112                 }
113         // ----------------------------------------------------------------------------------
114         }//ecapsename
115 }//ecapsename
116