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()));
110 sizer -> Add(button, 0, wxALL | wxALIGN_CENTER, 3);
111 sizer -> Add(new wxStaticText(panel,-1,title), 0, wxALL | wxALIGN_CENTER, 3);
115 button = new wxButton( panel, -1, title);
116 sizer -> Add(button,1,wxEXPAND | wxALL | wxALIGN_CENTER, 5);
118 Connect( button->GetId(), wxEVT_COMMAND_BUTTON_CLICKED ,
119 (wxObjectEventFunction)
120 (void (wxPanel::*)(wxEvent&))
121 &BitmapButtonWidget::OnClick );
125 panel -> SetSizer(sizer);
129 BitmapButtonWidget::~BitmapButtonWidget()
134 void BitmapButtonWidget::OnClick( wxEvent& )
136 // Look for the interpreter or the executer if no interpreter
137 bbtk::Interpreter::Pointer I;
138 bbtk::VirtualExec::Pointer E;
139 if (box->bbGetParent() != 0)
141 bbtk::Factory::Pointer f = boost::dynamic_pointer_cast<bbtk::ComplexBlackBoxDescriptor>(box->bbGetParent()->bbGetDescriptor())->GetFactory();
145 E = f->GetExecuter();
146 I = E->GetInterpreter();
151 // bbtkError("CommandButton::DoProcess() : could not find interpreter");
154 // If no executer : create a totally independant interpreter
155 I = bbtk::Interpreter::New();
159 // If executer : create an interpreter using E
160 I = bbtk::Interpreter::New(E);
164 std::string commandstr(box->bbGetInputIn());
166 // bbtk::Interpreter::mGlobalInterpreter->InterpretLine( commandstr );
170 pos2 = commandstr.find(";",pos1);
171 std::string ccommand;
177 ccommand=commandstr.substr(pos1,commandstr.length()-pos1 );
181 ccommand=commandstr.substr(pos1,pos2-pos1);
183 for ( i=0 ; i < ccommand.length() ; i++)
185 if (ccommand[i]==39) // '
190 I->InterpretLine( ccommand );
192 pos2 = commandstr.find(";",pos2+1);
198 box->bbSignalOutputModification();
201 void BitmapButtonWidget::SetLabel(wxString title)
203 button->SetLabel(title);
206 void BitmapButtonWidget::SetColour(wxColour color)
208 button->SetBackgroundColour(color);
211 void BitmapButtonWidget::SetIcon( wxBitmap* bitmap)
215 wxPanel* panel = this;
219 button = new wxBitmapButton(panel, -1, *bitmap, wxDefaultPosition, wxSize(bitmap->GetWidth(),bitmap->GetHeight()));
221 Connect( button->GetId(), wxEVT_COMMAND_BUTTON_CLICKED ,
222 (wxObjectEventFunction)
223 (void (wxPanel::*)(wxEvent&))
224 &BitmapButtonWidget::OnClick );
226 sizer->Add(button, 0, wxALL | wxALIGN_CENTER, 3);
227 sizer -> Add(new wxStaticText(panel,-1,title), 0, wxALL | wxALIGN_CENTER, 3);
228 sizer->RecalcSizes();