1 #ifndef __interfMENUBARH__
2 #define __interfMENUBARH__
9 #include <wx/bmpbuttn.h>
10 #include <wx/stattext.h>
13 //#include "interfMainPanel.h"
14 //#include "wxContourEventHandler.h"
21 interfMenuBar(wxWindow * parent, int sizex, int sizey)
22 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN){
23 //this initialice all the handlers to load any type of image, in this case the png handler is needed
24 wxInitAllImageHandlers();
30 virtual void initButtons(wxEvtHandler* evtHandler) = 0;
33 ** This method add a series of button in a line, it uses the method getbutton to create the button
34 ** and static text to create the text, it also initialice the flexgridsizer to add the buttons and
35 ** the text into the panel
36 ** @param vector path, this parameter contains the path of the images to include in the path
37 ** @param vector nom, this parameter contains the names corresponding to each path of image given
39 virtual void addButtons(std::vector<std::string> vpath, std::vector<std::string> vnom){
44 flexsizer = new wxFlexGridSizer(2,vpath.size(),2,2);
45 this->SetSizer(flexsizer, true);
46 this->SetAutoLayout( true );
48 //first row of the sizer, the buttons are being added
49 for(int i = 0; i < (int)(vpath.size());i++){
50 std::string p = vpath[i];
51 wxBitmapButton* bitmapbutton = this->getButton(p, sizex, sizey);
52 flexsizer->Add(bitmapbutton,wxFIXED_MINSIZE);
55 //second row of the sizer, the names are being added
57 for(int i = 0; i < (int)(vnom.size()); i++){
58 //sizex = vectbutton[i]->GetSize().GetWidth();
59 std::string n = vnom[i];
60 vectbutton[i]->SetToolTip(wxString(n.c_str(),wxConvUTF8));
61 //wxStaticText* statictext = getText(n, sizex, 15);
62 //flexsizer->Add(statictext, wxEXPAND |wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTRE_HORIZONTAL|wxSHAPED);
68 ** This method creates the button with the given image and returns it
69 ** @param string imgpath is the string containing the path to the image of the button being created
70 ** @param int x indicates the x coordinate where the button should be located
71 ** @param int y indicates the y coordinate where the button should be located
74 virtual wxBitmapButton* getButton(std::string imgpath, int sizex, int sizey){
75 vectimgpath.push_back(imgpath);
78 wxBitmap* bitmap = new wxBitmap(wxString(imgpath.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
81 wxBitmapButton* bitmapbutton = new wxBitmapButton(this, -1, *bitmap, wxDefaultPosition, wxDefaultSize,
82 wxBU_AUTODRAW, wxDefaultValidator, wxString(_T("")));
84 vectbutton.push_back(bitmapbutton);
89 ** This method create the static text with the given string and returns it, it also push it back into
91 ** @param string nom text wich will be added to the statictext
92 ** @param int sizex size of the text
93 ** @param int sizey size of the text
95 virtual wxStaticText* getText(std::string nom, int sizex, int sizey){
96 vectnom.push_back(nom);
97 return new wxStaticText(this, -1, wxString(nom.c_str(),wxConvUTF8), wxDefaultPosition,
98 wxSize(sizex,sizey), wxALIGN_CENTRE, wxString(nom.c_str(),wxConvUTF8));
101 ** Sets the vector funcion, this vector must contain a function for each button created
102 ** they must be ordered in the same way as the vector that contains the image path
103 ** and name of the button. See addButton(<vect>, <vect>)
105 virtual void setVectorFunction(std::vector<wxObjectEventFunction> vectf){
106 for(int i = 0; i < (int)(vectf.size());i++){
107 vectfunct.push_back(vectf[i]);
112 ** This method connect the events seted in the vector vectfunct
113 ** each function must have a button to relate with, see function setVectorFunction()
115 virtual void connectEvents(wxEvtHandler* evtHandler){
117 for(int i = 0; i < (int)(vectbutton.size());i++){
118 Connect(vectbutton[i]->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, vectfunct[i],NULL,evtHandler);
123 ** This method connect the events seted in the vector vectfunct
124 ** each function must have a button to relate with, see function setVectorFunction()
126 virtual void connectEvents(){
128 for(int i = 0; i < (int)(vectbutton.size());i++){
129 Connect(vectbutton[i]->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, vectfunct[i],NULL,vecthand[i]);
134 ** Sets the name of the button, this is used to relate the name of the button to a specific command
135 ** @params int i index in the array of buttons use fuction setVectorFuncion(<vect>) to set the vector
137 ** @params const char name of the button see wxContour_ActionCommandsID.h to view the commands
139 virtual void setButtonName(int i, const char c){
140 if(i < (int)(vectbutton.size())){
141 std::string ac = c+"";
142 vectbutton[i]->SetName(wxString(ac.c_str(),wxConvUTF8));
147 ** Responds to the events of the buttons, when the same panel is responsible for it. It gets the name
148 ** of the button corresponding to the method that has to be executed,
149 ** it uses attribute eventHandler to call the methods define by the application.
150 ** see setEventHandler(wxEventHandler*)
152 void onActionButtonPressed( wxCommandEvent& event )
154 if(true)//if(eventHandler!=NULL)
156 std::string theStr = std::string( ((wxButton *)event.GetEventObject())->GetName().ToAscii());
157 const char * toolCommand = theStr.c_str();
158 event.SetId( GetId() );
159 event.SetEventObject( this );
160 event.SetClientData( (void *) toolCommand);
161 //eventHandler->ProcessEvent( event );
165 virtual void setEventHandlers(std::vector<wxEvtHandler*> hand){
167 for(int i = 0; i < (int)(hand.size());i++){
168 vecthand.push_back(hand[i]);
173 std::vector<std::string> vectimgpath;
174 std::vector<std::string> vectnom;
176 std::vector<wxButton*> vectbutton;
177 std::vector<wxObjectEventFunction> vectfunct;
178 std::vector<wxEvtHandler*> vecthand;
180 wxFlexGridSizer* flexsizer;
183 //wxEvtHandler* eventHandler;