]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxInputText.cxx
=== MAJOR RELEASE ====
[bbtk.git] / packages / wx / src / bbwxInputText.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbwxInputText.cxx,v $
5   Language:  C++
6   Date:      $Date: 2008/04/18 12:59:52 $
7   Version:   $Revision: 1.2 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18 /**
19  *  \file 
20  *  \brief 
21  */
22
23
24 #ifdef _USE_WXWIDGETS_
25
26
27 #include "bbwxInputText.h"
28 #include "bbwxPackage.h"
29 //#include <wx/dialog.h>
30
31
32         
33
34
35 namespace bbwx
36 {
37   BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,InputText);
38   
39   
40   InputTextWidget::InputTextWidget(InputText* box,
41                                    wxWindow *parent, 
42                                    wxString In, 
43                                    wxString title)
44     : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
45       mBox(box)
46   {
47     wxPanel                     *panel  = this;
48     
49     mwxTextCtrl = new wxTextCtrl( panel, -1, In,
50                                   wxDefaultPosition, wxSize(800,20));
51     Connect( mwxTextCtrl->GetId(),  wxEVT_COMMAND_TEXT_UPDATED, 
52              (wxObjectEventFunction) 
53              (wxEventFunction)
54              (wxCommandEventFunction) 
55              (void (wxPanel::*)(wxCommandEvent&))
56              &InputTextWidget::OnTextUpdate ); 
57     
58     
59     wxFlexGridSizer *sizer      = new wxFlexGridSizer(1);
60     /*
61       if (title!=_T(""))
62       {
63     */
64     mwxTitle = new wxStaticText(panel,-1, title ); 
65     sizer       -> Add( mwxTitle ); 
66     //    }
67     sizer       -> Add( mwxTextCtrl,1,wxGROW ); 
68     sizer       -> AddGrowableCol(0);
69     
70     panel       -> SetSizer(sizer);
71     panel       -> SetAutoLayout(true);
72     panel       -> Layout();
73
74   }
75   //-------------------------------------------------------------------------
76   
77   InputTextWidget::~InputTextWidget()
78   {
79   }
80
81   //-------------------------------------------------------------------------
82   
83  
84    void InputTextWidget::SetTitle(wxString s)
85   { 
86     mwxTitle->SetLabel(s);
87   }
88
89   //-------------------------------------------------------------------------
90   std::string InputTextWidget::GetValue()
91   { 
92     return bbtk::wx2std ( mwxTextCtrl->GetValue() );
93   }
94
95   //--------------------------------------------------------------------------
96   void InputTextWidget::OnTextUpdate(wxCommandEvent& event)
97   {
98     mBox->bbSetOutputOut( GetValue() );
99     mBox->bbSetInputIn( GetValue() );
100     mBox->bbSignalOutputModification("Out");
101   }
102
103   //--------------------------------------------------------------------------
104   //-------------------------------------------------------------------------
105   //--------------------------------------------------------------------------
106   //--------------------------------------------------------------------------
107
108
109   BBTK_BLACK_BOX_IMPLEMENTATION(InputText,bbtk::WxBlackBox);
110
111
112
113   void InputText::bbUserConstructor() 
114   { 
115     bbSetInputTitle("");
116     bbSetInputIn("");
117   }
118   
119
120   void InputText::Process() 
121   { 
122     InputTextWidget *w=(InputTextWidget *)bbGetOutputWidget();
123     bbSetInputIn( w->GetValue() );
124     bbSetOutputOut( w->GetValue() );
125     w->SetTitle( bbtk::std2wx ( bbGetInputTitle() ) );
126   }
127   
128
129
130   void InputText::CreateWidget()
131   {
132     bbSetOutputWidget
133       ( (wxWindow*) new InputTextWidget(this, bbGetWxParent(),
134                                         bbtk::std2wx ( bbGetInputIn() ) , 
135                                         bbtk::std2wx ( bbGetInputTitle() ) ) );
136         
137   }
138
139
140
141
142 }//namespace bbtk
143
144 #endif // _USE_WXWIDGETS_ 
145