X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3f2b72b2403dd29aa93167ce0ce7d20e1d20f1bd..0d8b87ac8ae0ababd4c0d725142532f6d592fdb2:/samples/mobile/wxedit/wxedit.cpp diff --git a/samples/mobile/wxedit/wxedit.cpp b/samples/mobile/wxedit/wxedit.cpp index fe983016ef..5798973d77 100644 --- a/samples/mobile/wxedit/wxedit.cpp +++ b/samples/mobile/wxedit/wxedit.cpp @@ -59,23 +59,23 @@ MyFrame::MyFrame( wxWindow *parent, wxWindowID id, const wxString &title, // Create menu and status bar. CreateMyMenuBar(); CreateStatusBar(1); - SetStatusText( "Welcome to wxEdit!" ); + SetStatusText( _T("Welcome to wxEdit!") ); // Create edit control. Since it is the only // control in the frame, it will be resized // to file it out. - m_text = new wxTextCtrl( this, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE ); + m_text = new wxTextCtrl( this, -1, _T(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE ); // Read .ini file for file history etc. wxConfig *conf = (wxConfig*) wxConfig::Get(); int entries = 0; - conf->Read( "/History/Count", &entries ); + conf->Read( _T("/History/Count"), &entries ); for (int i = 0; i < entries; i++) { wxString tmp; - tmp.Printf( "/History/File%d", (int)i ); + tmp.Printf( _T("/History/File%d"), (int)i ); wxString res; conf->Read( tmp, &res ); @@ -123,48 +123,48 @@ void MyFrame::AddToHistory( const wxString &fname ) void MyFrame::CreateMyMenuBar() { wxMenu *file_menu = new wxMenu; - file_menu->Append( ID_ABOUT, "About...", "Program info" ); + file_menu->Append( ID_ABOUT, _T("About..."), _T("Program info") ); file_menu->AppendSeparator(); - file_menu->Append( ID_NEW, "New...", "New text" ); - file_menu->Append( ID_OPEN, "Open...", "Open text" ); - file_menu->Append( ID_SAVE, "Save", "Save text" ); - file_menu->Append( ID_SAVEAS, "Save as...", "Save text as..." ); + file_menu->Append( ID_NEW, _T("New..."), _T("New text") ); + file_menu->Append( ID_OPEN, _T("Open..."), _T("Open text") ); + file_menu->Append( ID_SAVE, _T("Save"), _T("Save text") ); + file_menu->Append( ID_SAVEAS, _T("Save as..."), _T("Save text as...") ); file_menu->AppendSeparator(); - file_menu->Append( ID_QUIT, "Quit...", "Quit program" ); + file_menu->Append( ID_QUIT, _T("Quit..."), _T("Quit program") ); wxMenu *edit_menu = new wxMenu; - edit_menu->Append( ID_COPY, "Copy" ); - edit_menu->Append( ID_CUT, "Cut" ); - edit_menu->Append( ID_PASTE, "Paste" ); + edit_menu->Append( ID_COPY, _T("Copy") ); + edit_menu->Append( ID_CUT, _T("Cut") ); + edit_menu->Append( ID_PASTE, _T("Paste") ); edit_menu->AppendSeparator(); - edit_menu->Append( ID_DELETE, "Delete" ); + edit_menu->Append( ID_DELETE, _T("Delete") ); wxMenu *history_menu = new wxMenu; - history_menu->Append( ID_LAST_1, "No file." ); - history_menu->Append( ID_LAST_2, "No file." ); - history_menu->Append( ID_LAST_3, "No file." ); + history_menu->Append( ID_LAST_1, _T("No file.") ); + history_menu->Append( ID_LAST_2, _T("No file.") ); + history_menu->Append( ID_LAST_3, _T("No file.") ); wxMenuBar *menu_bar = new wxMenuBar(); - menu_bar->Append( file_menu, "&File" ); - menu_bar->Append( edit_menu, "&Edit" ); - menu_bar->Append( history_menu, "&History" ); + menu_bar->Append( file_menu, _T("&File") ); + menu_bar->Append( edit_menu, _T("&Edit") ); + menu_bar->Append( history_menu, _T("&History") ); SetMenuBar( menu_bar ); } -void MyFrame::OnCopy( wxCommandEvent &event ) +void MyFrame::OnCopy( wxCommandEvent& WXUNUSED(event) ) { } -void MyFrame::OnCut( wxCommandEvent &event ) +void MyFrame::OnCut( wxCommandEvent& WXUNUSED(event) ) { } -void MyFrame::OnPaste( wxCommandEvent &event ) +void MyFrame::OnPaste( wxCommandEvent& WXUNUSED(event) ) { } -void MyFrame::OnDelete( wxCommandEvent &event ) +void MyFrame::OnDelete( wxCommandEvent& WXUNUSED(event) ) { } @@ -177,17 +177,27 @@ void MyFrame::OnLastFiles( wxCommandEvent &event ) size_t index = event.GetId() - ID_LAST_1; - wxASSERT( index < m_history.GetCount() ); - + if( index < m_history.GetCount() ) + { m_filename = m_history[index]; m_text->Clear(); m_text->LoadFile( m_filename ); SetStatusText( m_filename ); + } + else + { + wxMessageBox( + _T("This entry is empty. It should be filled once you will start opening."), + _T("Empty entry"), + wxOK | wxICON_INFORMATION, + this + ); + } } -void MyFrame::OnNew( wxCommandEvent &event ) +void MyFrame::OnNew( wxCommandEvent& WXUNUSED(event) ) { if (!Discard()) return; @@ -198,16 +208,15 @@ void MyFrame::OnNew( wxCommandEvent &event ) m_filename = wxEmptyString; - SetStatusText( "" ); + SetStatusText( _T("") ); } -void MyFrame::OnOpen( wxCommandEvent &event ) +void MyFrame::OnOpen( wxCommandEvent& WXUNUSED(event) ) { if (!Discard()) return; - wxFileDialog dialog( this, "Open text", "", "", - "Text file (*.txt)|*.txt|" - "Any file (*)|*", + wxFileDialog dialog( this, _T("Open text"), _T(""), _T(""), + _T("Text file (*.txt)|*.txt|Any file (*)|*"), wxOPEN|wxFILE_MUST_EXIST ); if (dialog.ShowModal() == wxID_OK) { @@ -215,22 +224,22 @@ void MyFrame::OnOpen( wxCommandEvent &event ) #ifdef __WXX11__ wxFileName fname( dialog.GetPath() ); - if ((fname.GetExt() == "cpp") || - (fname.GetExt() == "c") || - (fname.GetExt() == "h") || - (fname.GetExt() == "cxx") || - (fname.GetExt() == "hxx")) + if ((fname.GetExt() == _T("cpp")) || + (fname.GetExt() == _T("c")) || + (fname.GetExt() == _T("h")) || + (fname.GetExt() == _T("cxx")) || + (fname.GetExt() == _T("hxx"))) { m_text->SetLanguage( wxSOURCE_LANG_CPP ); } else - if (fname.GetExt() == "py") + if (fname.GetExt() == _T("py")) { m_text->SetLanguage( wxSOURCE_LANG_PYTHON ); } else - if ((fname.GetExt() == "pl") || - (fname.GetExt() == "pm")) + if ((fname.GetExt() == _T("pl")) || + (fname.GetExt() == _T("pm"))) { m_text->SetLanguage( wxSOURCE_LANG_PYTHON ); } @@ -247,19 +256,15 @@ void MyFrame::OnOpen( wxCommandEvent &event ) } } -void MyFrame::OnSave( wxCommandEvent &event ) +void MyFrame::OnSave( wxCommandEvent& WXUNUSED(event) ) { - if (m_filename.empty()) - OnSaveAs( event ); - else - m_text->SaveFile( m_filename ); + Save(); } -void MyFrame::OnSaveAs( wxCommandEvent &event ) +void MyFrame::OnSaveAs( wxCommandEvent& WXUNUSED(event) ) { - wxFileDialog dialog( this, "Open text", "", "", - "Text file (*.txt)|*.txt|" - "Any file (*)|*", + wxFileDialog dialog( this, _T("Open text"), _T(""), _T(""), + _T("Text file (*.txt)|*.txt|Any file (*)|*"), wxSAVE|wxOVERWRITE_PROMPT ); if (dialog.ShowModal() == wxID_OK) { @@ -270,21 +275,26 @@ void MyFrame::OnSaveAs( wxCommandEvent &event ) } } -void MyFrame::OnAbout( wxCommandEvent &event ) +void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) ) { - wxMessageDialog dialog( this, "Welcome to wxEdit\n(C)opyright Robert Roebling", - "About wxEdit", wxOK|wxICON_INFORMATION ); + wxMessageDialog dialog( this, _T("Welcome to wxEdit\n(C)opyright Robert Roebling"), + _T("About wxEdit"), wxOK|wxICON_INFORMATION ); dialog.ShowModal(); } -void MyFrame::OnQuit( wxCommandEvent &event ) +void MyFrame::OnQuit( wxCommandEvent& WXUNUSED(event) ) { Close( TRUE ); } bool MyFrame::Save() { - m_text->SaveFile(); + wxCommandEvent event; + + if (m_filename.empty()) + OnSaveAs( event ); + else + m_text->SaveFile( m_filename ); return TRUE; } @@ -293,8 +303,8 @@ bool MyFrame::Discard() { if (m_text->IsModified()) { - wxMessageDialog dialog( this, "Text has been\nmodified! Save?", - "wxEdit", wxYES_NO|wxCANCEL|wxICON_EXCLAMATION ); + wxMessageDialog dialog( this, _T("Text has been\nmodified! Save?"), + _T("wxEdit"), wxYES_NO|wxCANCEL|wxICON_EXCLAMATION ); int ret = dialog.ShowModal(); @@ -340,7 +350,7 @@ void MyFrame::OnUpdateUI( wxUpdateUIEvent &event ) } } -void MyFrame::OnCloseWindow( wxCloseEvent &event ) +void MyFrame::OnCloseWindow( wxCloseEvent& WXUNUSED(event) ) { // Save changes? if (!Discard()) return; @@ -356,12 +366,12 @@ void MyFrame::OnCloseWindow( wxCloseEvent &event ) if (m_history.GetCount() < (size_t)max) max = m_history.GetCount(); - conf->Write( "/History/Count", max ); + conf->Write( _T("/History/Count"), max ); for (int i = 0; i < max; i++) { wxString tmp; - tmp.Printf( "/History/File%d", (int)i ); + tmp.Printf( _T("/History/File%d"), (int)i ); conf->Write( tmp, m_history[(size_t)i] ); } @@ -385,10 +395,10 @@ MyApp::MyApp() bool MyApp::OnInit() { - SetVendorName("Free world"); - SetAppName("wxEdit"); + SetVendorName(_T("Free world")); + SetAppName(_T("wxEdit")); - MyFrame *frame = new MyFrame( NULL, -1, "wxEdit", wxPoint(20,20), wxSize(500,340) ); + MyFrame *frame = new MyFrame( NULL, -1, _T("wxEdit"), wxPoint(20,20), wxSize(500,340) ); frame->Show( TRUE ); return TRUE;