]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxInputText.cxx
no message
[bbtk.git] / packages / wx / src / bbwxInputText.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbwxInputText.cxx,v $
4   Language:  C++
5   Date:      $Date: 2011/07/22 12:30:31 $
6   Version:   $Revision: 1.12 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31 /**
32  *  \file 
33  *  \brief 
34  */
35
36 #ifdef _USE_WXWIDGETS_
37
38 #include "bbwxInputText.h"
39 #include "bbwxPackage.h"
40 //#include <wx/dialog.h>
41
42
43 namespace bbwx
44 {
45  
46   //--------------------------------------------------------------------------
47   class InputTextWidget : wxPanel
48   {
49   public:
50     InputTextWidget(InputText* box, wxWindow *parent,
51                     wxString In, wxString title);
52     ~InputTextWidget();
53
54     std::string GetValue();
55         void SetValue(std::string value);
56
57     void OnTextEnter(wxCommandEvent& event);
58     void OnTextUpdate(wxCommandEvent& event);
59
60     void SetTitle(wxString);
61
62   private:
63     InputText    *mBox;
64     wxTextCtrl   *mwxTextCtrl;
65     wxStaticText *mwxTitle;
66   };
67   
68   //------------------------------------------------------------------------
69   //------------------------------------------------------------------------
70   //------------------------------------------------------------------------
71
72   InputTextWidget::InputTextWidget(InputText* box,
73                                    wxWindow *parent, 
74                                    wxString In, 
75                                    wxString title)
76     : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
77       mBox(box)
78   {
79     wxPanel                     *panel  = this;
80     
81     mwxTextCtrl = new wxTextCtrl( panel, -1, In,wxDefaultPosition, wxSize(800,20),wxTE_PROCESS_ENTER);
82     Connect( mwxTextCtrl->GetId(),  wxEVT_COMMAND_TEXT_ENTER, 
83              (wxObjectEventFunction) 
84              (wxEventFunction)
85              (wxCommandEventFunction) 
86              (void (wxPanel::*)(wxCommandEvent&))
87              &InputTextWidget::OnTextEnter ); 
88
89     Connect( mwxTextCtrl->GetId(),  wxEVT_COMMAND_TEXT_UPDATED, 
90              (wxObjectEventFunction) 
91              (wxEventFunction)
92              (wxCommandEventFunction) 
93              (void (wxPanel::*)(wxCommandEvent&))
94              &InputTextWidget::OnTextUpdate ); 
95
96
97     wxFlexGridSizer *sizer      = new wxFlexGridSizer(1);
98     mwxTitle = new wxStaticText(panel, -1, title ); 
99     sizer-> Add( mwxTitle ); 
100     sizer-> Add( mwxTextCtrl, 1, wxGROW ); 
101     sizer-> AddGrowableCol(0);
102     
103     panel-> SetSizer(sizer);
104     panel-> SetAutoLayout(true);
105     panel-> Layout();
106
107   }
108   //-------------------------------------------------------------------------
109   
110   InputTextWidget::~InputTextWidget()
111   {
112   }
113
114   //-------------------------------------------------------------------------
115   
116  
117    void InputTextWidget::SetTitle(wxString s)
118   { 
119     mwxTitle->SetLabel(s);
120   }
121
122   //-------------------------------------------------------------------------
123   std::string InputTextWidget::GetValue()
124   { 
125     return bbtk::wx2std ( mwxTextCtrl->GetValue() );
126   }
127         
128   void InputTextWidget::SetValue(std::string value)
129   { 
130         mwxTextCtrl->SetValue( bbtk::std2wx(value) ) ;
131   }
132         
133   //--------------------------------------------------------------------------
134   void InputTextWidget::OnTextUpdate(wxCommandEvent& event)
135   {
136         if (mBox->bbGetInputReactiveOnKeystroke()==2){
137             mBox->bbSetOutputOut( GetValue() );
138             mBox->bbSetInputIn( GetValue() );
139             mBox->bbSignalOutputModification("Out");
140         }
141   }
142
143   //--------------------------------------------------------------------------
144   void InputTextWidget::OnTextEnter(wxCommandEvent& event)
145   {
146         if (mBox->bbGetInputReactiveOnKeystroke()==1){
147             mBox->bbSetOutputOut( GetValue() );
148                 mBox->bbSetInputIn( GetValue() );
149                 mBox->bbSignalOutputModification("Out");
150         }
151   }
152
153
154   //--------------------------------------------------------------------------
155   //-------------------------------------------------------------------------
156   //--------------------------------------------------------------------------
157   //--------------------------------------------------------------------------
158
159   BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx, InputText);
160   BBTK_BLACK_BOX_IMPLEMENTATION(InputText, bbtk::WxBlackBox);
161
162   
163         //-----------------------------------------------------------------     
164         void InputText::bbUserSetDefaultValues()
165         {
166                 firsttime=true;
167                 bbSetInputTitle("");
168                 bbSetInputIn("");
169                 bbSetOutputWidget(0);
170                 bbSetInputReactiveOnKeystroke(2);
171         }
172         
173         //-----------------------------------------------------------------     
174         void InputText::bbUserInitializeProcessing()
175         {
176         }
177         
178         //-----------------------------------------------------------------     
179         void InputText::bbUserFinalizeProcessing()
180         {
181         }
182
183         
184         //-----------------------------------------------------------------     
185   void InputText::Process() 
186   { 
187     InputTextWidget *w=(InputTextWidget *)bbGetOutputWidget();
188         if (w) 
189         {
190                 if (firsttime==true)
191                 {
192                         firsttime=false;
193                         w->SetValue(  bbGetInputIn().c_str() );
194                 }
195                 w->SetTitle( bbtk::std2wx ( bbGetInputTitle() ) );
196                 bbSetOutputOut( w->GetValue() );
197         } else {
198           bbSetOutputOut( "<VOID>" );
199         }
200   }
201   
202
203
204   void InputText::CreateWidget(wxWindow* parent)
205   {
206     bbSetOutputWidget
207       ( (wxWindow*) new InputTextWidget(this, //bbGetWxParent(),
208                                         parent,
209                                         bbtk::std2wx ( bbGetInputIn() ) , 
210                                         bbtk::std2wx ( bbGetInputTitle() ) ) ); 
211   }
212
213 }//namespace bbtk
214
215 #endif // _USE_WXWIDGETS_ 
216