1 #include "bbwxBitmapButton.h"
2 #include "bbwxPackage.h"
3 #include "bbtkInterpreter.h"
4 #include "bbtkExecuter.h"
7 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,BitmapButton)
8 BBTK_BLACK_BOX_IMPLEMENTATION(BitmapButton,bbtk::WxBlackBox);
10 void BitmapButton::Process()
12 BitmapButtonWidget* w = (BitmapButtonWidget*)bbGetOutputWidget();
21 void BitmapButton::CreateWidget(wxWindow* parent)
24 new BitmapButtonWidget(
28 bbtk::std2wx(bbGetInputLabel())
34 void BitmapButton::bbUserSetDefaultValues()
37 bbSetInputBitmap(NULL);
39 colorVector defaultColor;
40 defaultColor.push_back(0.75);
41 defaultColor.push_back(0.75);
42 defaultColor.push_back(0.75);
43 bbSetInputColour(defaultColor);
47 void BitmapButton::bbUserInitializeProcessing()
52 void BitmapButton::bbUserFinalizeProcessing()
57 void BitmapButton::UpdateColour()
59 BitmapButtonWidget* w = (BitmapButtonWidget*)bbGetOutputWidget();
60 if ((bbGetInputColour()[0] == -1) &&
61 (bbGetInputColour()[1] == -1) &&
62 (bbGetInputColour()[2] == -1)
65 w->SetColour( w->GetParent()->GetBackgroundColour() );
69 int r=(int) (255*bbGetInputColour()[0]);
70 int g=(int) (255*bbGetInputColour()[1]);
71 int b=(int) (255*bbGetInputColour()[2]);
72 w->SetColour( wxColour(r,g,b) );
77 void BitmapButton::UpdateLabel()
79 BitmapButtonWidget* w = (BitmapButtonWidget*)bbGetOutputWidget();
80 w->SetLabel( bbtk::std2wx( bbGetInputLabel() ) );
83 void BitmapButton::UpdateIcon()
85 if(bbGetInputBitmap() != NULL)
87 BitmapButtonWidget* w = (BitmapButtonWidget*)bbGetOutputWidget();
88 w->SetIcon(bbGetInputBitmap());
92 //--------------------------------------------------------------------------
94 BitmapButtonWidget::BitmapButtonWidget(
99 ) : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
103 wxPanel* panel = this;
104 sizer = new wxBoxSizer(wxHORIZONTAL);
108 button = new wxBitmapButton(panel, -1, *bitmap, wxDefaultPosition, wxSize(bitmap->GetWidth(),bitmap->GetHeight()));
109 std::cout << "Size: " << bitmap->GetWidth() << " " << bitmap->GetHeight() << std::endl;
113 button = new wxButton( panel, -1, title);
115 Connect( button->GetId(), wxEVT_COMMAND_BUTTON_CLICKED ,
116 (wxObjectEventFunction)
117 (void (wxPanel::*)(wxEvent&))
118 &BitmapButtonWidget::OnClick );
120 sizer -> Add(button,1,wxEXPAND | wxALL, 5);
122 panel -> SetSizer(sizer);
126 BitmapButtonWidget::~BitmapButtonWidget()
131 void BitmapButtonWidget::OnClick( wxEvent& )
133 // Look for the interpreter or the executer if no interpreter
134 bbtk::Interpreter::Pointer I;
135 bbtk::VirtualExec::Pointer E;
136 if (box->bbGetParent() != 0)
138 bbtk::Factory::Pointer f = boost::dynamic_pointer_cast<bbtk::ComplexBlackBoxDescriptor>(box->bbGetParent()->bbGetDescriptor())->GetFactory();
142 E = f->GetExecuter();
143 I = E->GetInterpreter();
148 // bbtkError("CommandButton::DoProcess() : could not find interpreter");
151 // If no executer : create a totally independant interpreter
152 I = bbtk::Interpreter::New();
156 // If executer : create an interpreter using E
157 I = bbtk::Interpreter::New(E);
161 std::string commandstr(box->bbGetInputIn());
163 // bbtk::Interpreter::mGlobalInterpreter->InterpretLine( commandstr );
167 pos2 = commandstr.find(";",pos1);
168 std::string ccommand;
174 ccommand=commandstr.substr(pos1,commandstr.length()-pos1 );
178 ccommand=commandstr.substr(pos1,pos2-pos1);
180 for ( i=0 ; i < ccommand.length() ; i++)
182 if (ccommand[i]==39) // '
187 I->InterpretLine( ccommand );
189 pos2 = commandstr.find(";",pos2+1);
195 box->bbSignalOutputModification();
198 void BitmapButtonWidget::SetLabel(wxString title)
200 button->SetLabel(title);
203 void BitmapButtonWidget::SetColour(wxColour color)
205 button->SetBackgroundColour(color);
208 void BitmapButtonWidget::SetIcon( wxBitmap* bitmap)
212 wxPanel* panel = this;
216 button = new wxBitmapButton(panel, -1, *bitmap, wxDefaultPosition, wxSize(bitmap->GetWidth(),bitmap->GetHeight()));
218 Connect( button->GetId(), wxEVT_COMMAND_BUTTON_CLICKED ,
219 (wxObjectEventFunction)
220 (void (wxPanel::*)(wxEvent&))
221 &BitmapButtonWidget::OnClick );
223 sizer->Add(button, 0, wxALL, 5);
224 sizer->RecalcSizes();