1 #ifndef __interfMENUBARH__
2 #define __interfMENUBARH__
8 #include <wx/bmpbuttn.h>
9 #include <wx/stattext.h>
12 //#include "interfMainPanel.h"
13 //#include "wxContourEventHandler.h"
20 interfMenuBar(wxWindow * parent, int sizex, int sizey)
21 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN){
22 //this initialice all the handlers to load any type of image, in this case the png handler is needed
23 wxInitAllImageHandlers();
29 virtual void initButtons(wxEvtHandler* evtHandler) = 0;
32 ** This method add a series of button in a line, it uses the method getbutton to create the button
33 ** and static text to create the text, it also initialice the flexgridsizer to add the buttons and
34 ** the text into the panel
35 ** @param vector path, this parameter contains the path of the images to include in the path
36 ** @param vector nom, this parameter contains the names corresponding to each path of image given
38 virtual void addButtons(std::vector<std::string> vpath, std::vector<std::string> vnom){
43 flexsizer = new wxFlexGridSizer(2,vpath.size(),2,2);
44 this->SetSizer(flexsizer, true);
45 this->SetAutoLayout( true );
47 //first row of the sizer, the buttons are being added
48 for(int i = 0; i < vpath.size();i++){
49 std::string p = vpath[i];
50 wxBitmapButton* bitmapbutton = this->getButton(p, sizex, sizey);
51 flexsizer->Add(bitmapbutton,wxFIXED_MINSIZE);
54 //second row of the sizer, the names are being added
56 for(int i = 0; i < vnom.size(); i++){
57 //sizex = vectbutton[i]->GetSize().GetWidth();
58 std::string n = vnom[i];
59 vectbutton[i]->SetToolTip(wxString(n.c_str(),wxConvUTF8));
60 //wxStaticText* statictext = getText(n, sizex, 15);
61 //flexsizer->Add(statictext, wxEXPAND |wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTRE_HORIZONTAL|wxSHAPED);
67 ** This method creates the button with the given image and returns it
68 ** @param string imgpath is the string containing the path to the image of the button being created
69 ** @param int x indicates the x coordinate where the button should be located
70 ** @param int y indicates the y coordinate where the button should be located
73 virtual wxBitmapButton* getButton(std::string imgpath, int sizex, int sizey){
74 vectimgpath.push_back(imgpath);
77 wxBitmap* bitmap = new wxBitmap(wxString(imgpath.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
80 wxBitmapButton* bitmapbutton = new wxBitmapButton(this, -1, *bitmap, wxDefaultPosition, wxDefaultSize,
81 wxBU_AUTODRAW, wxDefaultValidator, wxString(_T("")));
83 vectbutton.push_back(bitmapbutton);
88 ** This method create the static text with the given string and returns it, it also push it back into
90 ** @param string nom text wich will be added to the statictext
91 ** @param int sizex size of the text
92 ** @param int sizey size of the text
94 virtual wxStaticText* getText(std::string nom, int sizex, int sizey){
95 vectnom.push_back(nom);
96 return new wxStaticText(this, -1, wxString(nom.c_str(),wxConvUTF8), wxDefaultPosition,
97 wxSize(sizex,sizey), wxALIGN_CENTRE, wxString(nom.c_str(),wxConvUTF8));
100 ** Sets the vector funcion, this vector must contain a function for each button created
101 ** they must be ordered in the same way as the vector that contains the image path
102 ** and name of the button. See addButton(<vect>, <vect>)
104 virtual void setVectorFunction(std::vector<wxObjectEventFunction> vectf){
105 for(int i = 0; i < vectf.size();i++){
106 vectfunct.push_back(vectf[i]);
111 ** This method connect the events seted in the vector vectfunct
112 ** each function must have a button to relate with, see function setVectorFunction()
114 virtual void connectEvents(wxEvtHandler* evtHandler){
116 for(int i = 0; i < vectbutton.size();i++){
117 Connect(vectbutton[i]->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, vectfunct[i],NULL,evtHandler);
122 ** This method connect the events seted in the vector vectfunct
123 ** each function must have a button to relate with, see function setVectorFunction()
125 virtual void connectEvents(){
127 for(int i = 0; i < vectbutton.size();i++){
128 Connect(vectbutton[i]->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, vectfunct[i],NULL,vecthand[i]);
133 ** Sets the name of the button, this is used to relate the name of the button to a specific command
134 ** @params int i index in the array of buttons use fuction setVectorFuncion(<vect>) to set the vector
136 ** @params const char name of the button see wxContour_ActionCommandsID.h to view the commands
138 virtual void setButtonName(int i, const char c){
139 if(i < vectbutton.size()){
140 std::string ac = c+"";
141 vectbutton[i]->SetName(wxString(ac.c_str(),wxConvUTF8));
146 ** Responds to the events of the buttons, when the same panel is responsible for it. It gets the name
147 ** of the button corresponding to the method that has to be executed,
148 ** it uses attribute eventHandler to call the methods define by the application.
149 ** see setEventHandler(wxEventHandler*)
151 void onActionButtonPressed( wxCommandEvent& event )
153 if(true)//if(eventHandler!=NULL)
155 std::string theStr = std::string( ((wxButton *)event.GetEventObject())->GetName().ToAscii());
156 const char * toolCommand = theStr.c_str();
157 event.SetId( GetId() );
158 event.SetEventObject( this );
159 event.SetClientData( (void *) toolCommand);
160 //eventHandler->ProcessEvent( event );
164 virtual void setEventHandlers(std::vector<wxEvtHandler*> hand){
166 for(int i = 0; i < hand.size();i++){
167 vecthand.push_back(hand[i]);
172 std::vector<std::string> vectimgpath;
173 std::vector<std::string> vectnom;
175 std::vector<wxButton*> vectbutton;
176 std::vector<wxObjectEventFunction> vectfunct;
177 std::vector<wxEvtHandler*> vecthand;
179 wxFlexGridSizer* flexsizer;
182 //wxEvtHandler* eventHandler;