00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00037 #ifdef _USE_WXWIDGETS_
00038
00039
00040 #include "bbwxCommandButton.h"
00041 #include "bbwxPackage.h"
00042 #include "bbtkInterpreter.h"
00043 #include "bbtkExecuter.h"
00044
00045
00046
00047 namespace bbwx
00048 {
00049 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,CommandButton);
00050
00051 CommandButtonWidget::CommandButtonWidget(CommandButton* box,
00052 wxWindow *parent,
00053 wxString title )
00054 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
00055 mBox(box)
00056 {
00057
00058 wxPanel *panel = this;
00059
00060 mwxCommandButton = new wxButton( panel, -1, title);
00061 Connect( mwxCommandButton->GetId(), wxEVT_COMMAND_BUTTON_CLICKED ,
00062 (wxObjectEventFunction)
00063 (void (wxPanel::*)(wxEvent&))
00064 &CommandButtonWidget::OnCommandButton );
00065
00066 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
00067 sizer -> Add( mwxCommandButton,1,wxGROW | wxALL,10 );
00068 sizer -> AddGrowableCol(0);
00069
00070 panel -> SetSizer(sizer);
00071 panel -> SetAutoLayout(true);
00072 panel -> Layout();
00073
00074 }
00075
00076 CommandButtonWidget::~CommandButtonWidget()
00077 {
00078 }
00079
00080
00081 void CommandButtonWidget::OnCommandButton( wxEvent& )
00082 {
00083
00084 bbtk::Interpreter::Pointer I;
00085 bbtk::VirtualExec::Pointer E;
00086 if (mBox->bbGetParent() != 0)
00087 {
00088 bbtk::Factory::Pointer f = boost::dynamic_pointer_cast<bbtk::ComplexBlackBoxDescriptor>(mBox->bbGetParent()->bbGetDescriptor())->GetFactory();
00089 if ((f != 0)&&
00090 (f->GetExecuter()))
00091 {
00092 E = f->GetExecuter();
00093 I = E->GetInterpreter();
00094 }
00095 }
00096 if (I==0)
00097 {
00098
00099 if (E==0)
00100 {
00101
00102 I = bbtk::Interpreter::New();
00103 }
00104 else
00105 {
00106
00107 I = bbtk::Interpreter::New(E);
00108 }
00109 }
00110
00111 std::string commandstr(mBox->bbGetInputIn());
00112
00113
00114 unsigned int i;
00115 bool ok=true;
00116 int pos1=0,pos2;
00117 pos2 = commandstr.find(";",pos1);
00118 std::string ccommand;
00119 while (ok==true)
00120 {
00121 if (pos2==-1)
00122 {
00123 ok=false;
00124 ccommand=commandstr.substr(pos1,commandstr.length()-pos1 );
00125 }
00126 else
00127 {
00128 ccommand=commandstr.substr(pos1,pos2-pos1);
00129 }
00130 for ( i=0 ; i < ccommand.length() ; i++)
00131 {
00132 if (ccommand[i]==39)
00133 {
00134 ccommand[i]=34;
00135 }
00136 }
00137 I->InterpretLine( ccommand );
00138 pos1=pos2+1;
00139 pos2 = commandstr.find(";",pos2+1);
00140
00141 }
00142
00143 mBox->UpdateLabel();
00144 mBox->UpdateColour();
00145 mBox->bbSignalOutputModification();
00146 }
00147
00148
00149
00150
00151 void CommandButtonWidget::SetLabel(wxString title)
00152 {
00153 mwxCommandButton->SetLabel(title);
00154 }
00155
00156
00157 void CommandButtonWidget::SetColour(wxColour color)
00158 {
00159 mwxCommandButton->SetBackgroundColour(color);
00160 }
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 BBTK_BLACK_BOX_IMPLEMENTATION(CommandButton,bbtk::WxBlackBox);
00171
00172 void CommandButton::bbUserConstructor()
00173 {
00174 bbSetInputIn("");
00175 bbSetInputLabel("");
00176 std::vector<double> lstColour;
00177 lstColour.push_back(0.75);
00178 lstColour.push_back(0.75);
00179 lstColour.push_back(0.75);
00180 bbSetInputColour(lstColour);
00181 }
00182
00183
00184 void CommandButton::Process()
00185 {
00186 UpdateColour();
00187 UpdateLabel();
00188 }
00189
00190 void CommandButton::UpdateColour()
00191 {
00192 CommandButtonWidget* wxwidget = (CommandButtonWidget*)bbGetOutputWidget();
00193 if ( (bbGetInputColour()[0]==-1) &&
00194 (bbGetInputColour()[1]==-1) &&
00195 (bbGetInputColour()[2]==-1) )
00196 {
00197 wxwidget->SetColour( wxwidget->GetParent()->GetBackgroundColour() );
00198 }
00199 else
00200 {
00201 int r=(int) (255*bbGetInputColour()[0]);
00202 int g=(int) (255*bbGetInputColour()[1]);
00203 int b=(int) (255*bbGetInputColour()[2]);
00204 wxwidget->SetColour( wxColour(r,g,b) );
00205 }
00206
00207 }
00208 void CommandButton::UpdateLabel()
00209 {
00210 CommandButtonWidget* wxwidget = (CommandButtonWidget*)bbGetOutputWidget();
00211 wxwidget->SetLabel( bbtk::std2wx( bbGetInputLabel() ) );
00212 }
00213
00219 void CommandButton::CreateWidget()
00220 {
00221 bbSetOutputWidget
00222 ( new CommandButtonWidget ( this, bbGetWxParent(),
00223 bbtk::std2wx(bbGetInputLabel()) ) );
00224 UpdateColour();
00225 }
00226
00227
00228 }
00229
00230 #endif // _USE_WXWIDGETS_
00231