]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxInputText.cxx
7aaeeff92d4399bc60699d53e906ee88262d65ac
[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/09 14:02:15 $
6   Version:   $Revision: 1.10 $
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 OnTextEnter(wxCommandEvent& event);
56     void OnTextUpdate(wxCommandEvent& event);
57
58     void SetTitle(wxString);
59
60   private:
61     InputText    *mBox;
62     wxTextCtrl   *mwxTextCtrl;
63     wxStaticText *mwxTitle;
64   };
65   
66   //------------------------------------------------------------------------
67   //------------------------------------------------------------------------
68   //------------------------------------------------------------------------
69
70   InputTextWidget::InputTextWidget(InputText* box,
71                                    wxWindow *parent, 
72                                    wxString In, 
73                                    wxString title)
74     : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
75       mBox(box)
76   {
77     wxPanel                     *panel  = this;
78     
79     mwxTextCtrl = new wxTextCtrl( panel, -1, In,wxDefaultPosition, wxSize(800,20),wxTE_PROCESS_ENTER);
80     Connect( mwxTextCtrl->GetId(),  wxEVT_COMMAND_TEXT_ENTER, 
81              (wxObjectEventFunction) 
82              (wxEventFunction)
83              (wxCommandEventFunction) 
84              (void (wxPanel::*)(wxCommandEvent&))
85              &InputTextWidget::OnTextEnter ); 
86
87     Connect( mwxTextCtrl->GetId(),  wxEVT_COMMAND_TEXT_UPDATED, 
88              (wxObjectEventFunction) 
89              (wxEventFunction)
90              (wxCommandEventFunction) 
91              (void (wxPanel::*)(wxCommandEvent&))
92              &InputTextWidget::OnTextUpdate ); 
93
94
95     wxFlexGridSizer *sizer      = new wxFlexGridSizer(1);
96     mwxTitle = new wxStaticText(panel, -1, title ); 
97     sizer-> Add( mwxTitle ); 
98     sizer-> Add( mwxTextCtrl, 1, wxGROW ); 
99     sizer-> AddGrowableCol(0);
100     
101     panel-> SetSizer(sizer);
102     panel-> SetAutoLayout(true);
103     panel-> Layout();
104
105   }
106   //-------------------------------------------------------------------------
107   
108   InputTextWidget::~InputTextWidget()
109   {
110   }
111
112   //-------------------------------------------------------------------------
113   
114  
115    void InputTextWidget::SetTitle(wxString s)
116   { 
117     mwxTitle->SetLabel(s);
118   }
119
120   //-------------------------------------------------------------------------
121   std::string InputTextWidget::GetValue()
122   { 
123     return bbtk::wx2std ( mwxTextCtrl->GetValue() );
124   }
125
126   //--------------------------------------------------------------------------
127   void InputTextWidget::OnTextUpdate(wxCommandEvent& event)
128   {
129         if (mBox->bbGetInputReactiveOnKeystroke()==2){
130             mBox->bbSetOutputOut( GetValue() );
131             mBox->bbSetInputIn( GetValue() );
132             mBox->bbSignalOutputModification("Out");
133         }
134   }
135
136   //--------------------------------------------------------------------------
137   void InputTextWidget::OnTextEnter(wxCommandEvent& event)
138   {
139         if (mBox->bbGetInputReactiveOnKeystroke()==1){
140             mBox->bbSetOutputOut( GetValue() );
141                 mBox->bbSetInputIn( GetValue() );
142                 mBox->bbSignalOutputModification("Out");
143         }
144   }
145
146
147   //--------------------------------------------------------------------------
148   //-------------------------------------------------------------------------
149   //--------------------------------------------------------------------------
150   //--------------------------------------------------------------------------
151
152   BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx, InputText);
153   BBTK_BLACK_BOX_IMPLEMENTATION(InputText, bbtk::WxBlackBox);
154
155   
156         //-----------------------------------------------------------------     
157         void InputText::bbUserSetDefaultValues()
158         {
159                 bbSetInputTitle("");
160                 bbSetInputIn("");
161                 bbSetOutputWidget(0);
162                 bbSetInputReactiveOnKeystroke(2);
163         }
164         
165         //-----------------------------------------------------------------     
166         void InputText::bbUserInitializeProcessing()
167         {
168         }
169         
170         //-----------------------------------------------------------------     
171         void InputText::bbUserFinalizeProcessing()
172         {
173         }
174
175         
176         //-----------------------------------------------------------------     
177   void InputText::Process() 
178   { 
179     InputTextWidget *w=(InputTextWidget *)bbGetOutputWidget();
180         if (w) 
181         {
182                 bbSetInputIn( w->GetValue() );
183                 w->SetTitle( bbtk::std2wx ( bbGetInputTitle() ) );
184         }
185         bbSetOutputOut( bbGetInputIn() );
186   }
187   
188
189
190   void InputText::CreateWidget(wxWindow* parent)
191   {
192     bbSetOutputWidget
193       ( (wxWindow*) new InputTextWidget(this, //bbGetWxParent(),
194                                         parent,
195                                         bbtk::std2wx ( bbGetInputIn() ) , 
196                                         bbtk::std2wx ( bbGetInputTitle() ) ) ); 
197   }
198
199 }//namespace bbtk
200
201 #endif // _USE_WXWIDGETS_ 
202