]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxInputText.cxx
99c8a1939b637dcde83e7c8936727363bb7423e9
[bbtk.git] / packages / wx / src / bbwxInputText.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbwxInputText.cxx,v $
4   Language:  C++
5   Date:      $Date: 2009/12/02 15:13:25 $
6   Version:   $Revision: 1.7 $
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     Connect( mwxTextCtrl->GetId(),  wxEVT_COMMAND_TEXT_UPDATED, 
82              (wxObjectEventFunction) 
83              (wxEventFunction)
84              (wxCommandEventFunction) 
85              (void (wxPanel::*)(wxCommandEvent&))
86              &InputTextWidget::OnTextUpdate ); 
87
88     wxFlexGridSizer *sizer      = new wxFlexGridSizer(1);
89     /*
90       if (title!=_T(""))
91       {
92     */
93     mwxTitle = new wxStaticText(panel, -1, title ); 
94     sizer-> Add( mwxTitle ); 
95     //    }
96     sizer-> Add( mwxTextCtrl, 1, wxGROW ); 
97     sizer-> AddGrowableCol(0);
98     
99     panel-> SetSizer(sizer);
100     panel-> SetAutoLayout(true);
101     panel-> Layout();
102
103   }
104   //-------------------------------------------------------------------------
105   
106   InputTextWidget::~InputTextWidget()
107   {
108   }
109
110   //-------------------------------------------------------------------------
111   
112  
113    void InputTextWidget::SetTitle(wxString s)
114   { 
115     mwxTitle->SetLabel(s);
116   }
117
118   //-------------------------------------------------------------------------
119   std::string InputTextWidget::GetValue()
120   { 
121     return bbtk::wx2std ( mwxTextCtrl->GetValue() );
122   }
123
124   //--------------------------------------------------------------------------
125   void InputTextWidget::OnTextUpdate(wxCommandEvent& event)
126   {
127     mBox->bbSetOutputOut( GetValue() );
128     mBox->bbSetInputIn( GetValue() );
129     mBox->bbSignalOutputModification("Out");
130   }
131
132   //--------------------------------------------------------------------------
133   //-------------------------------------------------------------------------
134   //--------------------------------------------------------------------------
135   //--------------------------------------------------------------------------
136
137   BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx, InputText);
138   BBTK_BLACK_BOX_IMPLEMENTATION(InputText, bbtk::WxBlackBox);
139
140   
141         //-----------------------------------------------------------------     
142         void InputText::bbUserSetDefaultValues()
143         {
144                 bbSetInputTitle("");
145                 bbSetInputIn("");
146                 bbSetOutputWidget(0);
147         }
148         
149         //-----------------------------------------------------------------     
150         void InputText::bbUserInitializeProcessing()
151         {
152         }
153         
154         //-----------------------------------------------------------------     
155         void InputText::bbUserFinalizeProcessing()
156         {
157         }
158
159         
160         //-----------------------------------------------------------------     
161   void InputText::Process() 
162   { 
163     InputTextWidget *w=(InputTextWidget *)bbGetOutputWidget();
164         if (w) 
165         {
166                 bbSetInputIn( w->GetValue() );
167                 w->SetTitle( bbtk::std2wx ( bbGetInputTitle() ) );
168         }
169         bbSetOutputOut( bbGetInputIn() );
170   }
171   
172
173
174   void InputText::CreateWidget(wxWindow* parent)
175   {
176     bbSetOutputWidget
177       ( (wxWindow*) new InputTextWidget(this, //bbGetWxParent(),
178                                         parent,
179                                         bbtk::std2wx ( bbGetInputIn() ) , 
180                                         bbtk::std2wx ( bbGetInputTitle() ) ) ); 
181   }
182
183 }//namespace bbtk
184
185 #endif // _USE_WXWIDGETS_ 
186