interfMenuBar.h

Go to the documentation of this file.
00001 #ifndef __interfMENUBARH__
00002 #define __interfMENUBARH__
00003 
00004 #include <string>
00005 #include <wx/wx.h>
00006 #include <vector>
00007 #include <wx/image.h>
00008 #include <wx/bitmap.h>
00009 #include <wx/bmpbuttn.h>
00010 #include <wx/stattext.h>
00011 #include <wx/sizer.h>
00012 
00013 //#include "interfMainPanel.h"
00014 //#include "wxContourEventHandler.h"
00015 
00016 
00017 class interfMenuBar :
00018         public wxPanel
00019 {
00020 public:
00021         interfMenuBar(wxWindow * parent, int sizex, int sizey)
00022                 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN){
00023                 //this initialice all the handlers to load any type of image, in this case the png handler is needed
00024                 wxInitAllImageHandlers();
00025                 
00026                                 
00027         }
00028         //~interfMenuBar();
00029 
00030         virtual void initButtons(wxEvtHandler* evtHandler) = 0;
00031 
00039     virtual void addButtons(std::vector<std::string> vpath, std::vector<std::string> vnom){
00040                 
00041                 int sizex = 80;
00042                 int sizey = 80;
00043         
00044                 //RaC 11-09
00045                 //This constructor function as well but it is neccessary to change vpath.size() by 6
00046                 //flexsizer = new wxFlexGridSizer(2,vpath.size(),2,2);
00047                 flexsizer = new wxFlexGridSizer(6);
00048                 this->SetSizer(flexsizer, true);
00049                 this->SetAutoLayout( true );
00050                 
00051                 //first row of the sizer, the buttons are being added
00052                 for(int i = 0; i < (int)(vpath.size());i++){
00053                         std::string p = vpath[i];
00054                         wxBitmapButton* bitmapbutton = this->getButton(p, sizex, sizey);
00055                         flexsizer->Add(bitmapbutton,wxFIXED_MINSIZE);
00056                         
00057                 }
00058                 //second row of the sizer, the names are being added
00059                 
00060                 for(int i = 0; i < (int)(vnom.size()); i++){
00061                         //sizex = vectbutton[i]->GetSize().GetWidth();
00062                         std::string n = vnom[i];
00063                         vectbutton[i]->SetToolTip(wxString(n.c_str(),wxConvUTF8));
00064                         //wxStaticText* statictext = getText(n, sizex, 15);
00065                         //flexsizer->Add(statictext, wxEXPAND |wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTRE_HORIZONTAL|wxSHAPED);
00066                 }
00067                 this->Layout();
00068         }
00069 
00077         virtual wxBitmapButton* getButton(std::string imgpath, int sizex, int sizey){
00078                 vectimgpath.push_back(imgpath);
00079                                 
00080                 
00081                 wxBitmap* bitmap = new wxBitmap(wxString(imgpath.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
00082 
00083                 //wxSize(sizex,sizey)
00084                 wxBitmapButton* bitmapbutton = new wxBitmapButton(this, -1, *bitmap, wxDefaultPosition, wxDefaultSize,
00085                                                                                         wxBU_AUTODRAW, wxDefaultValidator, wxString(_T("")));
00086 
00087                 vectbutton.push_back(bitmapbutton);
00088                 return bitmapbutton;
00089         }
00090 
00098         virtual wxStaticText* getText(std::string nom, int sizex, int sizey){
00099                 vectnom.push_back(nom);
00100                 return new wxStaticText(this, -1, wxString(nom.c_str(),wxConvUTF8), wxDefaultPosition, 
00101                                                                 wxSize(sizex,sizey), wxALIGN_CENTRE, wxString(nom.c_str(),wxConvUTF8));
00102         }
00108         virtual void setVectorFunction(std::vector<wxObjectEventFunction> vectf){
00109                 for(int i = 0; i < (int)(vectf.size());i++){
00110                         vectfunct.push_back(vectf[i]);
00111                 }               
00112         }
00113 
00118         virtual void connectEvents(wxEvtHandler* evtHandler){   
00119 
00120                 for(int i = 0; i < (int)(vectbutton.size());i++){
00121                         Connect(vectbutton[i]->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, vectfunct[i],NULL,evtHandler);
00122                 }
00123         }
00124 
00129         virtual void connectEvents(){   
00130 
00131                 for(int i = 0; i < (int)(vectbutton.size());i++){
00132                         Connect(vectbutton[i]->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, vectfunct[i],NULL,vecthand[i]);
00133                 }
00134         }
00135 
00142         virtual void setButtonName(int i, const char c){
00143                 if(i < (int)(vectbutton.size())){
00144                         std::string ac = c+"";
00145                         vectbutton[i]->SetName(wxString(ac.c_str(),wxConvUTF8));
00146                 }
00147         }
00148 
00155         void onActionButtonPressed( wxCommandEvent& event )
00156         {
00157                 if(true)//if(eventHandler!=NULL)
00158                 {
00159                         std::string theStr = std::string( ((wxButton *)event.GetEventObject())->GetName().ToAscii());
00160                         const char * toolCommand = theStr.c_str();
00161                         event.SetId( GetId() );
00162                         event.SetEventObject( this );
00163                         event.SetClientData( (void *) toolCommand);
00164                         //eventHandler->ProcessEvent( event );
00165                 }
00166         }
00167 
00168         virtual void setEventHandlers(std::vector<wxEvtHandler*> hand){
00169 
00170                 for(int i = 0; i < (int)(hand.size());i++){
00171                         vecthand.push_back(hand[i]);
00172                 }
00173         }
00174         
00175 private:
00176         std::vector<std::string> vectimgpath;
00177         std::vector<std::string> vectnom;
00178         
00179         std::vector<wxButton*> vectbutton;
00180         std::vector<wxObjectEventFunction> vectfunct;
00181         std::vector<wxEvtHandler*> vecthand;
00182 
00183         wxFlexGridSizer* flexsizer;
00184 
00185 protected:
00186         //wxEvtHandler* eventHandler;
00187         std::string datadir;
00188 
00189         
00190 
00191 };
00192 
00193 #endif

Generated on Wed Jun 27 23:28:32 2012 for creaContours_lib by  doxygen 1.5.7.1