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;
86 mwxTextCtrl = new wxTextCtrl( panel, -1, In,wxDefaultPosition, wxSize(800,20),wxTE_PROCESS_ENTER);
87 Connect( mwxTextCtrl->GetId(), wxEVT_COMMAND_TEXT_ENTER,
88 (wxObjectEventFunction)
90 (wxCommandEventFunction)
91 (void (wxPanel::*)(wxCommandEvent&))
92 &InputTextWidget::OnTextEnter );
94 Connect( mwxTextCtrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED,
95 (wxObjectEventFunction)
97 (wxCommandEventFunction)
98 (void (wxPanel::*)(wxCommandEvent&))
99 &InputTextWidget::OnTextUpdate );
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);
108 panel-> SetSizer(sizer);
109 panel-> SetAutoLayout(true);
113 //-------------------------------------------------------------------------
115 InputTextWidget::~InputTextWidget()
119 //-------------------------------------------------------------------------
122 void InputTextWidget::SetTitle(wxString s)
124 mwxTitle->SetLabel(s);
127 //-------------------------------------------------------------------------
128 std::string InputTextWidget::GetValue()
130 return bbtk::wx2std ( mwxTextCtrl->GetValue() );
133 void InputTextWidget::SetValue(std::string value)
135 mwxTextCtrl->SetValue( bbtk::std2wx(value) ) ;
138 //--------------------------------------------------------------------------
139 void InputTextWidget::OnTextUpdate(wxCommandEvent& event)
141 if (mBox->bbGetInputReactiveOnKeystroke()==2){
142 mBox->bbSetOutputOut( GetValue() );
143 mBox->bbSetInputIn( GetValue() );
144 mBox->bbSignalOutputModification("Out");
148 //--------------------------------------------------------------------------
149 void InputTextWidget::OnTextEnter(wxCommandEvent& event)
151 if (mBox->bbGetInputReactiveOnKeystroke()==1){
152 mBox->bbSetOutputOut( GetValue() );
153 mBox->bbSetInputIn( GetValue() );
154 mBox->bbSignalOutputModification("Out");
159 //--------------------------------------------------------------------------
160 //-------------------------------------------------------------------------
161 //--------------------------------------------------------------------------
162 //--------------------------------------------------------------------------
164 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx, InputText);
165 BBTK_BLACK_BOX_IMPLEMENTATION(InputText, bbtk::WxBlackBox);
168 //-----------------------------------------------------------------
169 void InputText::bbUserSetDefaultValues()
174 bbSetOutputWidget(0);
175 bbSetInputReactiveOnKeystroke(2);
178 //-----------------------------------------------------------------
179 void InputText::bbUserInitializeProcessing()
183 //-----------------------------------------------------------------
184 void InputText::bbUserFinalizeProcessing()
189 //-----------------------------------------------------------------
190 void InputText::Process()
192 InputTextWidget *w=(InputTextWidget *)bbGetOutputWidget();
198 w->SetValue( bbGetInputIn().c_str() );
200 w->SetTitle( bbtk::std2wx ( bbGetInputTitle() ) );
201 bbSetOutputOut( w->GetValue() );
203 bbSetOutputOut( "<VOID>" );
209 void InputText::CreateWidget(wxWindow* parent)
212 ( (wxWindow*) new InputTextWidget(this, //bbGetWxParent(),
214 bbtk::std2wx ( bbGetInputIn() ) ,
215 bbtk::std2wx ( bbGetInputTitle() ) ) );
220 #endif // _USE_WXWIDGETS_