]> 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/10/17 08:18:32 $
6   Version:   $Revision: 1.3 $
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   BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,InputText);
51   
52   
53   InputTextWidget::InputTextWidget(InputText* box,
54                                    wxWindow *parent, 
55                                    wxString In, 
56                                    wxString title)
57     : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
58       mBox(box)
59   {
60     wxPanel                     *panel  = this;
61     
62     mwxTextCtrl = new wxTextCtrl( panel, -1, In,
63                                   wxDefaultPosition, wxSize(800,20));
64     Connect( mwxTextCtrl->GetId(),  wxEVT_COMMAND_TEXT_UPDATED, 
65              (wxObjectEventFunction) 
66              (wxEventFunction)
67              (wxCommandEventFunction) 
68              (void (wxPanel::*)(wxCommandEvent&))
69              &InputTextWidget::OnTextUpdate ); 
70     
71     
72     wxFlexGridSizer *sizer      = new wxFlexGridSizer(1);
73     /*
74       if (title!=_T(""))
75       {
76     */
77     mwxTitle = new wxStaticText(panel,-1, title ); 
78     sizer       -> Add( mwxTitle ); 
79     //    }
80     sizer       -> Add( mwxTextCtrl,1,wxGROW ); 
81     sizer       -> AddGrowableCol(0);
82     
83     panel       -> SetSizer(sizer);
84     panel       -> SetAutoLayout(true);
85     panel       -> Layout();
86
87   }
88   //-------------------------------------------------------------------------
89   
90   InputTextWidget::~InputTextWidget()
91   {
92   }
93
94   //-------------------------------------------------------------------------
95   
96  
97    void InputTextWidget::SetTitle(wxString s)
98   { 
99     mwxTitle->SetLabel(s);
100   }
101
102   //-------------------------------------------------------------------------
103   std::string InputTextWidget::GetValue()
104   { 
105     return bbtk::wx2std ( mwxTextCtrl->GetValue() );
106   }
107
108   //--------------------------------------------------------------------------
109   void InputTextWidget::OnTextUpdate(wxCommandEvent& event)
110   {
111     mBox->bbSetOutputOut( GetValue() );
112     mBox->bbSetInputIn( GetValue() );
113     mBox->bbSignalOutputModification("Out");
114   }
115
116   //--------------------------------------------------------------------------
117   //-------------------------------------------------------------------------
118   //--------------------------------------------------------------------------
119   //--------------------------------------------------------------------------
120
121
122   BBTK_BLACK_BOX_IMPLEMENTATION(InputText,bbtk::WxBlackBox);
123
124
125
126   void InputText::bbUserConstructor() 
127   { 
128     bbSetInputTitle("");
129     bbSetInputIn("");
130   }
131   
132
133   void InputText::Process() 
134   { 
135     InputTextWidget *w=(InputTextWidget *)bbGetOutputWidget();
136     bbSetInputIn( w->GetValue() );
137     bbSetOutputOut( w->GetValue() );
138     w->SetTitle( bbtk::std2wx ( bbGetInputTitle() ) );
139   }
140   
141
142
143   void InputText::CreateWidget()
144   {
145     bbSetOutputWidget
146       ( (wxWindow*) new InputTextWidget(this, bbGetWxParent(),
147                                         bbtk::std2wx ( bbGetInputIn() ) , 
148                                         bbtk::std2wx ( bbGetInputTitle() ) ) );
149         
150   }
151
152
153
154
155 }//namespace bbtk
156
157 #endif // _USE_WXWIDGETS_ 
158