]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxInputText.cxx
revert for EVENT on Input Text
[bbtk.git] / packages / wx / src / bbwxInputText.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbwxInputText.cxx,v $
4   Language:  C++
5   Date:      $Date: 2010/04/08 14:36:32 $
6   Version:   $Revision: 1.9 $
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 OnTextUpdate(wxCommandEvent& event);
56
57     void SetTitle(wxString);
58
59   private:
60     InputText    *mBox;
61     wxTextCtrl   *mwxTextCtrl;
62     wxStaticText *mwxTitle;
63   };
64   
65   //------------------------------------------------------------------------
66   //------------------------------------------------------------------------
67   //------------------------------------------------------------------------
68
69   InputTextWidget::InputTextWidget(InputText* box,
70                                    wxWindow *parent, 
71                                    wxString In, 
72                                    wxString title)
73     : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
74       mBox(box)
75   {
76     wxPanel                     *panel  = this;
77     
78     mwxTextCtrl = new wxTextCtrl( panel, -1, In,
79                                   wxDefaultPosition, wxSize(800,20));
80
81     // The following was supposed to generate an event, only on ENTER key ...
82     // ... but nothing happens (no event at all ?!?)                      
83     //Connect( mwxTextCtrl->GetId(),  wxEVT_COMMAND_TEXT_ENTER,
84     
85      Connect( mwxTextCtrl->GetId(),  wxEVT_COMMAND_TEXT_UPDATED,     
86              (wxObjectEventFunction) 
87              (wxEventFunction)
88              (wxCommandEventFunction) 
89              (void (wxPanel::*)(wxCommandEvent&))
90              &InputTextWidget::OnTextUpdate ); 
91
92     wxFlexGridSizer *sizer      = new wxFlexGridSizer(1);
93     /*
94       if (title!=_T(""))
95       {
96     */
97     mwxTitle = new wxStaticText(panel, -1, title ); 
98     sizer-> Add( mwxTitle ); 
99     //    }
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   //--------------------------------------------------------------------------
129   void InputTextWidget::OnTextUpdate(wxCommandEvent& event)
130   {
131     mBox->bbSetOutputOut( GetValue() );
132     mBox->bbSetInputIn( GetValue() );
133     mBox->bbSignalOutputModification("Out");
134   }
135
136   //--------------------------------------------------------------------------
137   //-------------------------------------------------------------------------
138   //--------------------------------------------------------------------------
139   //--------------------------------------------------------------------------
140
141   BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx, InputText);
142   BBTK_BLACK_BOX_IMPLEMENTATION(InputText, bbtk::WxBlackBox);
143
144   
145         //-----------------------------------------------------------------     
146         void InputText::bbUserSetDefaultValues()
147         {
148                 bbSetInputTitle("");
149                 bbSetInputIn("");
150                 bbSetOutputWidget(0);
151         }
152         
153         //-----------------------------------------------------------------     
154         void InputText::bbUserInitializeProcessing()
155         {
156         }
157         
158         //-----------------------------------------------------------------     
159         void InputText::bbUserFinalizeProcessing()
160         {
161         }
162
163         
164         //-----------------------------------------------------------------     
165   void InputText::Process() 
166   { 
167     InputTextWidget *w=(InputTextWidget *)bbGetOutputWidget();
168         if (w) 
169         {
170                 bbSetInputIn( w->GetValue() );
171                 w->SetTitle( bbtk::std2wx ( bbGetInputTitle() ) );
172         }
173         bbSetOutputOut( bbGetInputIn() );
174   }
175   
176
177
178   void InputText::CreateWidget(wxWindow* parent)
179   {
180     bbSetOutputWidget
181       ( (wxWindow*) new InputTextWidget(this, //bbGetWxParent(),
182                                         parent,
183                                         bbtk::std2wx ( bbGetInputIn() ) , 
184                                         bbtk::std2wx ( bbGetInputTitle() ) ) ); 
185   }
186
187 }//namespace bbtk
188
189 #endif // _USE_WXWIDGETS_ 
190