]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxInputText.cxx
*** empty log message ***
[bbtk.git] / packages / wx / src / bbwxInputText.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbwxInputText.cxx,v $
4   Language:  C++
5   Date:      $Date: 2008/12/12 08:55:23 $
6   Version:   $Revision: 1.5 $
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
37 #ifdef _USE_WXWIDGETS_
38
39
40 #include "bbwxInputText.h"
41 #include "bbwxPackage.h"
42 //#include <wx/dialog.h>
43
44
45         
46
47
48 namespace bbwx
49 {
50
51
52
53
54   
55   //--------------------------------------------------------------------------
56   class InputTextWidget : wxPanel
57   {
58   public:
59     InputTextWidget(InputText* box, wxWindow *parent,
60                     wxString In, wxString title);
61     ~InputTextWidget();
62
63     std::string GetValue();
64     void OnTextUpdate(wxCommandEvent& event);
65
66     void SetTitle(wxString);
67
68   private:
69     InputText    *mBox;
70     wxTextCtrl   *mwxTextCtrl;
71     wxStaticText *mwxTitle;
72   };
73   
74   //------------------------------------------------------------------------
75   //------------------------------------------------------------------------
76   //------------------------------------------------------------------------
77
78   
79   
80   
81   InputTextWidget::InputTextWidget(InputText* box,
82                                    wxWindow *parent, 
83                                    wxString In, 
84                                    wxString title)
85     : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
86       mBox(box)
87   {
88     wxPanel                     *panel  = this;
89     
90     mwxTextCtrl = new wxTextCtrl( panel, -1, In,
91                                   wxDefaultPosition, wxSize(800,20));
92     Connect( mwxTextCtrl->GetId(),  wxEVT_COMMAND_TEXT_UPDATED, 
93              (wxObjectEventFunction) 
94              (wxEventFunction)
95              (wxCommandEventFunction) 
96              (void (wxPanel::*)(wxCommandEvent&))
97              &InputTextWidget::OnTextUpdate ); 
98     
99     
100     wxFlexGridSizer *sizer      = new wxFlexGridSizer(1);
101     /*
102       if (title!=_T(""))
103       {
104     */
105     mwxTitle = new wxStaticText(panel,-1, title ); 
106     sizer       -> Add( mwxTitle ); 
107     //    }
108     sizer       -> Add( mwxTextCtrl,1,wxGROW ); 
109     sizer       -> AddGrowableCol(0);
110     
111     panel       -> SetSizer(sizer);
112     panel       -> SetAutoLayout(true);
113     panel       -> Layout();
114
115   }
116   //-------------------------------------------------------------------------
117   
118   InputTextWidget::~InputTextWidget()
119   {
120   }
121
122   //-------------------------------------------------------------------------
123   
124  
125    void InputTextWidget::SetTitle(wxString s)
126   { 
127     mwxTitle->SetLabel(s);
128   }
129
130   //-------------------------------------------------------------------------
131   std::string InputTextWidget::GetValue()
132   { 
133     return bbtk::wx2std ( mwxTextCtrl->GetValue() );
134   }
135
136   //--------------------------------------------------------------------------
137   void InputTextWidget::OnTextUpdate(wxCommandEvent& event)
138   {
139     mBox->bbSetOutputOut( GetValue() );
140     mBox->bbSetInputIn( GetValue() );
141     mBox->bbSignalOutputModification("Out");
142   }
143
144   //--------------------------------------------------------------------------
145   //-------------------------------------------------------------------------
146   //--------------------------------------------------------------------------
147   //--------------------------------------------------------------------------
148
149   BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,InputText);
150   BBTK_BLACK_BOX_IMPLEMENTATION(InputText,bbtk::WxBlackBox);
151
152
153
154   void InputText::bbUserConstructor() 
155   { 
156     bbSetInputTitle("");
157     bbSetInputIn("");
158           bbSetOutputWidget(0);
159   }
160   
161
162   void InputText::Process() 
163   { 
164     InputTextWidget *w=(InputTextWidget *)bbGetOutputWidget();
165         if (w) 
166         {
167                 bbSetInputIn( w->GetValue() );
168                 w->SetTitle( bbtk::std2wx ( bbGetInputTitle() ) );
169         }
170         bbSetOutputOut( bbGetInputIn() );
171   }
172   
173
174
175   void InputText::CreateWidget(wxWindow* parent)
176   {
177     bbSetOutputWidget
178       ( (wxWindow*) new InputTextWidget(this, //bbGetWxParent(),
179                                                                                 parent,
180                                                                                 bbtk::std2wx ( bbGetInputIn() ) , 
181                                                                                 bbtk::std2wx ( bbGetInputTitle() ) ) );
182         
183   }
184
185
186
187
188 }//namespace bbtk
189
190 #endif // _USE_WXWIDGETS_ 
191