]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxInputText.cxx
3056f05f3abba7b24c9eb6071a1d81c139f83241
[bbtk.git] / packages / wx / src / bbwxInputText.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: bbwxInputText.cxx,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:52:14 $
33   Version:   $Revision: 1.13 $
34 =========================================================================*/
35
36 /**
37  *  \file 
38  *  \brief 
39  */
40
41 #ifdef _USE_WXWIDGETS_
42
43 #include "bbwxInputText.h"
44 #include "bbwxPackage.h"
45 //#include <wx/dialog.h>
46
47
48 namespace bbwx
49 {
50  
51   //--------------------------------------------------------------------------
52   class InputTextWidget : wxPanel
53   {
54   public:
55     InputTextWidget(InputText* box, wxWindow *parent,
56                     wxString In, wxString title);
57     ~InputTextWidget();
58
59     std::string GetValue();
60         void SetValue(std::string value);
61
62     void OnTextEnter(wxCommandEvent& event);
63     void OnTextUpdate(wxCommandEvent& event);
64
65     void SetTitle(wxString);
66
67   private:
68     InputText    *mBox;
69     wxTextCtrl   *mwxTextCtrl;
70     wxStaticText *mwxTitle;
71   };
72   
73   //------------------------------------------------------------------------
74   //------------------------------------------------------------------------
75   //------------------------------------------------------------------------
76
77   InputTextWidget::InputTextWidget(InputText* box,
78                                    wxWindow *parent, 
79                                    wxString In, 
80                                    wxString title)
81     : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
82       mBox(box)
83   {
84     wxPanel                     *panel  = this;
85     
86     mwxTextCtrl = new wxTextCtrl( panel, -1, In,wxDefaultPosition, wxSize(800,20),wxTE_PROCESS_ENTER);
87     Connect( mwxTextCtrl->GetId(),  wxEVT_COMMAND_TEXT_ENTER, 
88              (wxObjectEventFunction) 
89              (wxEventFunction)
90              (wxCommandEventFunction) 
91              (void (wxPanel::*)(wxCommandEvent&))
92              &InputTextWidget::OnTextEnter ); 
93
94     Connect( mwxTextCtrl->GetId(),  wxEVT_COMMAND_TEXT_UPDATED, 
95              (wxObjectEventFunction) 
96              (wxEventFunction)
97              (wxCommandEventFunction) 
98              (void (wxPanel::*)(wxCommandEvent&))
99              &InputTextWidget::OnTextUpdate ); 
100
101
102     wxFlexGridSizer *sizer      = new wxFlexGridSizer(1);
103     mwxTitle = new wxStaticText(panel, -1, title ); 
104     sizer-> Add( mwxTitle ); 
105     sizer-> Add( mwxTextCtrl, 1, wxGROW ); 
106     sizer-> AddGrowableCol(0);
107     
108     panel-> SetSizer(sizer);
109     panel-> SetAutoLayout(true);
110     panel-> Layout();
111
112   }
113   //-------------------------------------------------------------------------
114   
115   InputTextWidget::~InputTextWidget()
116   {
117   }
118
119   //-------------------------------------------------------------------------
120   
121  
122    void InputTextWidget::SetTitle(wxString s)
123   { 
124     mwxTitle->SetLabel(s);
125   }
126
127   //-------------------------------------------------------------------------
128   std::string InputTextWidget::GetValue()
129   { 
130     return bbtk::wx2std ( mwxTextCtrl->GetValue() );
131   }
132         
133   void InputTextWidget::SetValue(std::string value)
134   { 
135         mwxTextCtrl->SetValue( bbtk::std2wx(value) ) ;
136   }
137         
138   //--------------------------------------------------------------------------
139   void InputTextWidget::OnTextUpdate(wxCommandEvent& event)
140   {
141         if (mBox->bbGetInputReactiveOnKeystroke()==2){
142             mBox->bbSetOutputOut( GetValue() );
143             mBox->bbSetInputIn( GetValue() );
144             mBox->bbSignalOutputModification("Out");
145         }
146   }
147
148   //--------------------------------------------------------------------------
149   void InputTextWidget::OnTextEnter(wxCommandEvent& event)
150   {
151         if (mBox->bbGetInputReactiveOnKeystroke()==1){
152             mBox->bbSetOutputOut( GetValue() );
153                 mBox->bbSetInputIn( GetValue() );
154                 mBox->bbSignalOutputModification("Out");
155         }
156   }
157
158
159   //--------------------------------------------------------------------------
160   //-------------------------------------------------------------------------
161   //--------------------------------------------------------------------------
162   //--------------------------------------------------------------------------
163
164   BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx, InputText);
165   BBTK_BLACK_BOX_IMPLEMENTATION(InputText, bbtk::WxBlackBox);
166
167   
168         //-----------------------------------------------------------------     
169         void InputText::bbUserSetDefaultValues()
170         {
171                 firsttime=true;
172                 bbSetInputTitle("");
173                 bbSetInputIn("");
174                 bbSetOutputWidget(0);
175                 bbSetInputReactiveOnKeystroke(2);
176         }
177         
178         //-----------------------------------------------------------------     
179         void InputText::bbUserInitializeProcessing()
180         {
181         }
182         
183         //-----------------------------------------------------------------     
184         void InputText::bbUserFinalizeProcessing()
185         {
186         }
187
188         
189         //-----------------------------------------------------------------     
190   void InputText::Process() 
191   { 
192     InputTextWidget *w=(InputTextWidget *)bbGetOutputWidget();
193         if (w) 
194         {
195                 if (firsttime==true)
196                 {
197                         firsttime=false;
198                         w->SetValue(  bbGetInputIn().c_str() );
199                 }
200                 w->SetTitle( bbtk::std2wx ( bbGetInputTitle() ) );
201                 bbSetOutputOut( w->GetValue() );
202         } else {
203           bbSetOutputOut( "<VOID>" );
204         }
205   }
206   
207
208
209   void InputText::CreateWidget(wxWindow* parent)
210   {
211     bbSetOutputWidget
212       ( (wxWindow*) new InputTextWidget(this, //bbGetWxParent(),
213                                         parent,
214                                         bbtk::std2wx ( bbGetInputIn() ) , 
215                                         bbtk::std2wx ( bbGetInputTitle() ) ) ); 
216   }
217
218 }//namespace bbtk
219
220 #endif // _USE_WXWIDGETS_ 
221