MatOCAD Logo

Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

NtbSheet.cpp

Go to the documentation of this file.
00001 #include "../../include/TabFogli/NtbSheet.h"
00002 
00003 DEFINE_EVENT_TYPE(EVT_COMMAND_PAGE_CLOSED)
00004 
00005 IMPLEMENT_CLASS(NtbSheet,wxNotebook)
00007 BEGIN_EVENT_TABLE(NtbSheet,wxNotebook)
00009 EVT_LEFT_DCLICK(NtbSheet::OnLeftDClick)
00010 EVT_RIGHT_DOWN(NtbSheet::OnRightDown)
00011 EVT_MENU(1125,NtbSheet::MnuChangeNameClick)
00012 EVT_MENU(1126,NtbSheet::MnuCloseClick)
00013 EVT_MENU(1127,NtbSheet::MnuCloseAllExceptThisClick)
00014 EVT_MENU(1128,NtbSheet::MnuCloseAllClick)
00016 END_EVENT_TABLE()
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 NtbSheet::NtbSheet(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) : wxNotebook(parent,id,pos,size,style,name)
00027 {
00028     pagen=0;
00029     PopLista =  new wxMenu(_("")  );
00030     PopLista->Append(1125,_("Cambia nome"),_("Cambia il nome del foglio corrente"), wxITEM_NORMAL);
00031     PopLista->Append(1126,_("Chiudi"),_("Chiude il foglio corrente"), wxITEM_NORMAL);
00032     PopLista->Append(1127,_("Chiudi tutti tranne questo"),_("Chiude tutti i fogli tranne il corrente"), wxITEM_NORMAL);
00033     PopLista->Append(1128,_("Chiudi tutti"),_("Chiude tutti i fogli"), wxITEM_NORMAL);
00034 
00035 }
00036 
00037 
00038 
00039 //Process the right-down event
00040 void NtbSheet::OnRightDown(wxMouseEvent& event)
00041 {
00042     click_position=HitTest(event.GetPosition());
00043 
00044     if(click_position!=wxNOT_FOUND)
00045         PopupMenu(PopLista);
00046     event.Skip();
00047 
00048 }
00049 
00050 void NtbSheet::MnuChangeNameClick(wxCommandEvent& event)
00051 {
00052     ChangeName();
00053 }
00054 
00055 /*
00056  * MnuDeleteClick
00057  */
00058 void NtbSheet::MnuCloseClick(wxCommandEvent& event)
00059 {
00060     // insert your code here
00061     DeletePage(click_position);
00062     wxCommandEvent cevent(EVT_COMMAND_PAGE_CLOSED, GetId() );
00063     event.SetEventObject( this );
00064     // Send it
00065     GetEventHandler()->ProcessEvent(cevent);
00066 }
00067 
00068 /*
00069  * MnuDeleteAllExceptThisClick
00070  */
00071 void NtbSheet::MnuCloseAllExceptThisClick(wxCommandEvent& event)
00072 {
00073     int n_page=GetPageCount();
00074 
00075 
00076     for(int i=0; i<n_page-1; i++)
00077         if(i<click_position)
00078             DeletePage(0);
00079         else
00080             DeletePage(1);
00081 
00082 
00083 
00084     wxCommandEvent cevent(EVT_COMMAND_PAGE_CLOSED, GetId() );
00085     event.SetEventObject( this );
00086     // Send it
00087     GetEventHandler()->ProcessEvent(cevent);
00088 }
00089 
00090 void NtbSheet::MnuCloseAllClick(wxCommandEvent& event)
00091 {
00092     int n_page=GetPageCount();
00093 
00094 
00095     for(int i=0; i<n_page; i++)
00096         DeletePage(0);
00097 
00098     wxCommandEvent cevent(EVT_COMMAND_PAGE_CLOSED, GetId() );
00099     cevent.SetEventObject( this );
00100     // Send it
00101     GetEventHandler()->ProcessEvent(cevent);
00102 }
00103 
00104 
00105 void NtbSheet::OnLeftDClick(wxMouseEvent& event)
00106 {
00107     click_position=HitTest(event.GetPosition());
00108 
00109     if(click_position!=wxNOT_FOUND)
00110         ChangeName();
00111     else
00112     {
00113         InsertPage();
00114     }
00115     event.Skip();
00116 
00117 }
00118 
00119 
00120 
00121 void NtbSheet::InsertPage()
00122 {
00123 
00124     wxString titolo;
00125 
00126    titolo.Printf(_T("Pagina%d"),pagen++);
00127     PnlFoglio *sheet =  new PnlFoglio((wxWindow*)this,wxID_ANY,wxPoint(4,24),GetSize(),wxTAB_TRAVERSAL ,titolo);
00128     AddPage((wxWindow*)sheet,titolo);
00129     SetSelection(GetPageCount()-1);
00130 }
00131 
00132 
00133 void NtbSheet::ChangeName()
00134 {
00135     bool changed=false;
00136 
00137     while(!changed)
00138     {
00139         wxString name = wxGetTextFromUser(_T("Inserisci nuovo nome"),_T("Cambia nome"));
00140         if(!name.IsEmpty())
00141         {
00142             bool found=false;
00143             for(int i=0;i<(int)GetPageCount();i++)
00144                 if(name.CmpNoCase(GetPageText(i))==0) //if they are equal
00145                     found=true;
00146             if(!found)
00147             {
00148                 SetPageText(click_position,name);
00149                 changed=true;
00150             }
00151             else
00152             {
00153                 wxMessageDialog* error=new wxMessageDialog(this,_T("Nome gia` esistente"),_T("errore"),wxICON_ERROR | wxOK);
00154                 error->ShowModal();
00155                 error->Destroy();
00156             }
00157         }
00158         else
00159         {
00160             wxMessageDialog* error=new wxMessageDialog(this,_T("Nome non valido"),_T("errore"));
00161             error->ShowModal();
00162             error->Destroy();
00163         }
00164     }
00165 }
00166 
00167 wxMenu* NtbSheet::GetPopUp()
00168 { return PopLista;
00169 }
00170 

 

SourceForge Logo