]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxLayoutTab.cxx
#3082 BBTK Bug New Normal - not compiling in CentOS 2.6
[bbtk.git] / packages / wx / src / bbwxLayoutTab.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbwxLayoutTab.cxx,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:52:14 $
33   Version:   $Revision: 1.12 $
34 =========================================================================*/
35
36 /**
37  *  \file 
38  *  \brief 
39  */
40
41
42 #ifdef _USE_WXWIDGETS_
43
44
45 #include "bbwxLayoutTab.h"
46 #include "bbwxPackage.h"
47 #include "bbtkUtilities.h"
48 #include "bbtkBlackBoxInputConnector.h"
49
50
51
52 namespace bbwx
53 {
54   BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx , LayoutTab);
55   
56
57   BBTK_BLACK_BOX_IMPLEMENTATION(LayoutTab,bbtk::WxBlackBox);
58   
59         //-----------------------------------------------------------------     
60         void LayoutTab::bbUserSetDefaultValues()
61         {
62                 bbSetInputOrientation("TOP");
63                 bbSetInputWidget1(NULL);
64                 bbSetInputWidget2(NULL);
65                 bbSetInputWidget3(NULL);
66                 bbSetInputWidget4(NULL);
67                 bbSetInputWidget5(NULL);
68                 bbSetInputWidget6(NULL);
69                 bbSetInputWidget7(NULL);
70                 bbSetInputWidget8(NULL);
71                 bbSetInputWidget9(NULL);
72         }
73         
74         //-----------------------------------------------------------------     
75         void LayoutTab::bbUserInitializeProcessing()
76         {
77         }
78         
79         //-----------------------------------------------------------------     
80         void LayoutTab::bbUserFinalizeProcessing()
81         {
82         }
83         
84         //-----------------------------------------------------------------     
85   void LayoutTab::TryInsertWindow(wxNotebook *book, const std::string& input )
86   {
87     wxWindow* w = bbCreateWidgetOfInput(input,book); //panel);
88     if (w!=NULL)
89     {
90                 book->AddPage(w,w->GetName());
91     }
92   }
93
94
95   void LayoutTab::SetTitleTabs()
96   {
97
98         std::vector<std::string> vecTitle;
99         std::vector<std::string> vecInputNameWidget;
100         vecInputNameWidget.push_back("Widget1");        
101         vecInputNameWidget.push_back("Widget2");        
102         vecInputNameWidget.push_back("Widget3");        
103         vecInputNameWidget.push_back("Widget4");        
104         vecInputNameWidget.push_back("Widget5");        
105         vecInputNameWidget.push_back("Widget6");        
106         vecInputNameWidget.push_back("Widget7");        
107         vecInputNameWidget.push_back("Widget8");        
108         vecInputNameWidget.push_back("Widget9");        
109         int iWidget,sizeVecInputNameWidget= vecInputNameWidget.size();
110         for (iWidget=0; iWidget<sizeVecInputNameWidget; iWidget++)
111         {
112                 bbtk::BlackBoxInputConnector* c = bbGetInputConnectorMap().find( vecInputNameWidget[iWidget] )->second ;
113         if ( c->IsConnected() )
114         {
115                         // Get black box from 
116                         BlackBox::Pointer from = c->GetConnection()->GetBlackBoxFrom();
117                         bbtk::WidgetBlackBox<wxWindow>::Pointer wfrom = boost::dynamic_pointer_cast<bbtk::WidgetBlackBox<wxWindow> >(from);
118                         vecTitle.push_back( wfrom->bbGetInputWinTitle() );
119                 } // if c
120         } // for iWidget
121
122
123         wxNotebook* w = (wxNotebook*)bbGetOutputWidget();
124         if (w!=NULL) 
125         {
126                 int i,size=vecTitle.size();
127                 for (i=0; i<size; i++)
128                 {
129                         w->SetPageText(i, wxString( vecTitle[i].c_str(),wxConvUTF8 ) ); 
130                 } // for i
131         } //w
132   }
133
134
135   void LayoutTab::Process() 
136   { 
137         PutWinTitle();
138         SetTitleTabs();
139   }
140   
141   
142   void LayoutTab::CreateWidget(wxWindow* parent) 
143   { 
144     long style = wxNB_TOP;
145     if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"0|T|TOP")==true) 
146       { style=wxNB_TOP; }
147     if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"1|R|RIGHT")==true)
148       { style=wxNB_RIGHT; }
149     if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"2|B|BOTTOM")==true)
150       { style=wxNB_BOTTOM; }
151     if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"3|L|LEFT")==true)
152       { style=wxNB_LEFT; }
153     wxNotebook *w = new wxNotebook(parent, //bbGetWxParent(),
154                                    -1, 
155                                    wxDefaultPosition,
156                                    wxDefaultSize,
157                                    style );
158     w->SetName( bbtk::std2wx( bbGetInputWinTitle() ) );
159     
160     TryInsertWindow(w,"Widget1");
161     TryInsertWindow(w,"Widget2");
162     TryInsertWindow(w,"Widget3");
163     TryInsertWindow(w,"Widget4");
164     TryInsertWindow(w,"Widget5");
165     TryInsertWindow(w,"Widget6");
166     TryInsertWindow(w,"Widget7");
167     TryInsertWindow(w,"Widget8");
168     TryInsertWindow(w,"Widget9");
169     
170     bbSetOutputWidget( w );
171   }
172   
173   
174   // This callback is necessary to get actual processing of the view 
175   // when window is shown
176   void  LayoutTab::OnShowWidget()
177   {
178     wxNotebook* w = (wxNotebook*)bbGetOutputWidget();
179     if (w) 
180       {
181         if (w->GetPageCount()>0)
182           {
183             w->SetSelection(0);
184             for (unsigned int i=0; i<w->GetPageCount(); ++i)  w->AdvanceSelection();
185           }
186       }
187     
188    
189   }
190
191
192 }//namespace bbwx
193
194 #endif
195