2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbwxInputText.cxx,v $
32 Date: $Date: 2012/11/16 08:52:14 $
33 Version: $Revision: 1.13 $
34 =========================================================================*/
41 #ifdef _USE_WXWIDGETS_
43 #include "bbwxInputText.h"
44 #include "bbwxPackage.h"
45 //#include <wx/dialog.h>
51 //--------------------------------------------------------------------------
52 class InputTextWidget : wxPanel
55 InputTextWidget(InputText* box, wxWindow *parent,
56 wxString In, wxString title );
59 std::string GetValue();
60 void SetValue(std::string value);
61 void SetWindowStyle(int style);
63 void OnTextEnter(wxCommandEvent& event);
64 void OnTextUpdate(wxCommandEvent& event);
66 void SetTitle(wxString);
70 wxTextCtrl *mwxTextCtrl;
71 wxStaticText *mwxTitle;
74 //------------------------------------------------------------------------
75 //------------------------------------------------------------------------
76 //------------------------------------------------------------------------
78 InputTextWidget::InputTextWidget(InputText* box,
82 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
85 wxPanel *panel = this;
88 //wxTE_MULTILINE For multiple line you have to create an other box (EED).
90 mwxTextCtrl = new wxTextCtrl( panel, -1, In,wxDefaultPosition, wxSize(800,40) , wxTE_PROCESS_ENTER);
91 Connect( mwxTextCtrl->GetId(), wxEVT_COMMAND_TEXT_ENTER,
92 (wxObjectEventFunction)
94 (wxCommandEventFunction)
95 (void (wxPanel::*)(wxCommandEvent&))
96 &InputTextWidget::OnTextEnter );
98 Connect( mwxTextCtrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED,
99 (wxObjectEventFunction)
101 (wxCommandEventFunction)
102 (void (wxPanel::*)(wxCommandEvent&))
103 &InputTextWidget::OnTextUpdate );
106 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
107 mwxTitle = new wxStaticText(panel, -1, title );
108 sizer-> Add( mwxTitle );
109 sizer-> Add( mwxTextCtrl, 1, wxGROW );
110 sizer-> AddGrowableCol(0);
112 panel-> SetSizer(sizer);
113 panel-> SetAutoLayout(true);
117 //-------------------------------------------------------------------------
119 InputTextWidget::~InputTextWidget()
123 //-------------------------------------------------------------------------
126 void InputTextWidget::SetTitle(wxString s)
128 mwxTitle->SetLabel(s);
131 void InputTextWidget::SetWindowStyle(int style)
133 long wxstyle = wxTE_PROCESS_ENTER;
134 if (style==1) {wxstyle = wxTE_PASSWORD;}
135 mwxTextCtrl->SetWindowStyle(wxstyle);
139 //-------------------------------------------------------------------------
140 std::string InputTextWidget::GetValue()
142 return bbtk::wx2std ( mwxTextCtrl->GetValue() );
145 void InputTextWidget::SetValue(std::string value)
147 mwxTextCtrl->SetValue( bbtk::std2wx(value) ) ;
150 //--------------------------------------------------------------------------
151 void InputTextWidget::OnTextUpdate(wxCommandEvent& event)
153 if (mBox->bbGetInputReactiveOnKeystroke()==2){
154 mBox->bbSetOutputOut( GetValue() );
155 mBox->bbSetInputIn( GetValue() );
156 mBox->bbSignalOutputModification("Out");
160 //--------------------------------------------------------------------------
161 void InputTextWidget::OnTextEnter(wxCommandEvent& event)
163 if (mBox->bbGetInputReactiveOnKeystroke()==1){
164 mBox->bbSetOutputOut( GetValue() );
165 mBox->bbSetInputIn( GetValue() );
166 mBox->bbSignalOutputModification("Out");
171 //--------------------------------------------------------------------------
172 //-------------------------------------------------------------------------
173 //--------------------------------------------------------------------------
174 //--------------------------------------------------------------------------
176 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx, InputText);
177 BBTK_BLACK_BOX_IMPLEMENTATION(InputText, bbtk::WxBlackBox);
180 //-----------------------------------------------------------------
181 void InputText::bbUserSetDefaultValues()
186 bbSetOutputWidget(0);
187 bbSetInputReactiveOnKeystroke(2);
191 //-----------------------------------------------------------------
192 void InputText::bbUserInitializeProcessing()
196 //-----------------------------------------------------------------
197 void InputText::bbUserFinalizeProcessing()
202 //-----------------------------------------------------------------
203 void InputText::Process()
205 InputTextWidget *w=(InputTextWidget *)bbGetOutputWidget();
211 w->SetValue( bbGetInputIn().c_str() );
213 w->SetWindowStyle( bbGetInputStyle() );
214 w->SetTitle( bbtk::std2wx ( bbGetInputTitle() ) );
215 bbSetOutputOut( w->GetValue() );
217 bbSetOutputOut( "<VOID>" );
223 void InputText::CreateWidget(wxWindow* parent)
226 ( (wxWindow*) new InputTextWidget( this, //bbGetWxParent(),
228 bbtk::std2wx ( bbGetInputIn() ) ,
229 bbtk::std2wx ( bbGetInputTitle() )
236 #endif // _USE_WXWIDGETS_