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);
62 void OnTextEnter(wxCommandEvent& event);
63 void OnTextUpdate(wxCommandEvent& event);
65 void SetTitle(wxString);
69 wxTextCtrl *mwxTextCtrl;
70 wxStaticText *mwxTitle;
73 //------------------------------------------------------------------------
74 //------------------------------------------------------------------------
75 //------------------------------------------------------------------------
77 InputTextWidget::InputTextWidget(InputText* box,
81 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
84 wxPanel *panel = this;
89 mwxTextCtrl = new wxTextCtrl( panel, -1, In,wxDefaultPosition, wxSize(80,80) , wxTE_PROCESS_ENTER);
90 Connect( mwxTextCtrl->GetId(), wxEVT_COMMAND_TEXT_ENTER,
91 (wxObjectEventFunction)
93 (wxCommandEventFunction)
94 (void (wxPanel::*)(wxCommandEvent&))
95 &InputTextWidget::OnTextEnter );
97 Connect( mwxTextCtrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED,
98 (wxObjectEventFunction)
100 (wxCommandEventFunction)
101 (void (wxPanel::*)(wxCommandEvent&))
102 &InputTextWidget::OnTextUpdate );
105 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
106 mwxTitle = new wxStaticText(panel, -1, title );
107 sizer-> Add( mwxTitle );
108 sizer-> Add( mwxTextCtrl, 1, wxEXPAND );
109 sizer-> AddGrowableCol(0);
111 panel-> SetSizer(sizer);
112 panel-> SetAutoLayout(true);
116 //-------------------------------------------------------------------------
118 InputTextWidget::~InputTextWidget()
122 //-------------------------------------------------------------------------
125 void InputTextWidget::SetTitle(wxString s)
127 mwxTitle->SetLabel(s);
130 //-------------------------------------------------------------------------
131 std::string InputTextWidget::GetValue()
133 return bbtk::wx2std ( mwxTextCtrl->GetValue() );
136 void InputTextWidget::SetValue(std::string value)
138 mwxTextCtrl->SetValue( bbtk::std2wx(value) ) ;
141 //--------------------------------------------------------------------------
142 void InputTextWidget::OnTextUpdate(wxCommandEvent& event)
144 if (mBox->bbGetInputReactiveOnKeystroke()==2){
145 mBox->bbSetOutputOut( GetValue() );
146 mBox->bbSetInputIn( GetValue() );
147 mBox->bbSignalOutputModification("Out");
151 //--------------------------------------------------------------------------
152 void InputTextWidget::OnTextEnter(wxCommandEvent& event)
154 if (mBox->bbGetInputReactiveOnKeystroke()==1){
155 mBox->bbSetOutputOut( GetValue() );
156 mBox->bbSetInputIn( GetValue() );
157 mBox->bbSignalOutputModification("Out");
162 //--------------------------------------------------------------------------
163 //-------------------------------------------------------------------------
164 //--------------------------------------------------------------------------
165 //--------------------------------------------------------------------------
167 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx, InputText);
168 BBTK_BLACK_BOX_IMPLEMENTATION(InputText, bbtk::WxBlackBox);
171 //-----------------------------------------------------------------
172 void InputText::bbUserSetDefaultValues()
177 bbSetOutputWidget(NULL);
178 bbSetInputReactiveOnKeystroke(2);
181 //-----------------------------------------------------------------
182 void InputText::bbUserInitializeProcessing()
186 //-----------------------------------------------------------------
187 void InputText::bbUserFinalizeProcessing()
192 //-----------------------------------------------------------------
193 void InputText::Process()
195 InputTextWidget *w=(InputTextWidget *)bbGetOutputWidget();
201 w->SetValue( bbGetInputIn().c_str() );
203 w->SetTitle( bbtk::std2wx ( bbGetInputTitle() ) );
204 bbSetOutputOut( w->GetValue() );
206 bbSetOutputOut( "<VOID>" );
212 void InputText::CreateWidget(wxWindow* parent)
215 ( (wxWindow*) new InputTextWidget( this, //bbGetWxParent(),
217 bbtk::std2wx ( bbGetInputIn() ) ,
218 bbtk::std2wx ( bbGetInputTitle() )
225 #endif // _USE_WXWIDGETS_