More wxEdit.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15046 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 2002-04-08 21:48:29 +00:00
parent 5d8301397c
commit a0760bd34b
2 changed files with 97 additions and 5 deletions

View File

@ -27,11 +27,22 @@
BEGIN_EVENT_TABLE(MyFrame,wxFrame)
EVT_MENU(ID_ABOUT, MyFrame::OnAbout)
EVT_MENU(ID_NEW, MyFrame::OnNew)
EVT_MENU(ID_OPEN, MyFrame::OnOpen)
EVT_MENU(ID_SAVE, MyFrame::OnSave)
EVT_MENU(ID_SAVEAS, MyFrame::OnSaveAs)
EVT_MENU(ID_QUIT, MyFrame::OnQuit)
EVT_MENU(ID_COPY, MyFrame::OnCopy)
EVT_MENU(ID_CUT, MyFrame::OnCut)
EVT_MENU(ID_PASTE, MyFrame::OnPaste)
EVT_MENU(ID_DELETE, MyFrame::OnDelete)
EVT_MENU(ID_LAST_1, MyFrame::OnLast1)
EVT_MENU(ID_LAST_2, MyFrame::OnLast2)
EVT_MENU(ID_LAST_3, MyFrame::OnLast3)
EVT_CLOSE(MyFrame::OnCloseWindow)
END_EVENT_TABLE()
@ -65,8 +76,38 @@ void MyFrame::CreateMyMenuBar()
SetMenuBar( menu_bar );
}
void MyFrame::OnCopy( wxCommandEvent &event )
{
}
void MyFrame::OnCut( wxCommandEvent &event )
{
}
void MyFrame::OnPaste( wxCommandEvent &event )
{
}
void MyFrame::OnDelete( wxCommandEvent &event )
{
}
void MyFrame::OnLast1( wxCommandEvent &event )
{
}
void MyFrame::OnLast2( wxCommandEvent &event )
{
}
void MyFrame::OnLast3( wxCommandEvent &event )
{
}
void MyFrame::OnNew( wxCommandEvent &event )
{
if (!Discard()) return;
m_text->Clear();
}
@ -121,8 +162,8 @@ void MyFrame::OnSaveAs( wxCommandEvent &event )
void MyFrame::OnAbout( wxCommandEvent &event )
{
wxMessageDialog dialog( this, "Welcome to SuperApp 1.0\n(C)opyright Joe Hacker",
"About SuperApp", wxOK|wxICON_INFORMATION );
wxMessageDialog dialog( this, "Welcome to wxEdit\n(C)opyright Robert Roebling",
"About wxEdit", wxOK|wxICON_INFORMATION );
dialog.ShowModal();
}
@ -131,10 +172,39 @@ void MyFrame::OnQuit( wxCommandEvent &event )
Close( TRUE );
}
bool MyFrame::Save()
{
m_text->SaveFile();
return TRUE;
}
bool MyFrame::Discard()
{
if (m_text->IsModified())
{
wxMessageDialog dialog( this, "Text has been modified! Save?",
"wxEdit", wxYES_NO|wxCANCEL|wxICON_EXCLAMATION );
int ret = dialog.ShowModal();
if (ret == wxID_CANCEL)
return FALSE;
if (ret == wxID_YES)
{
if (!Save())
return FALSE;
}
}
return TRUE;
}
void MyFrame::OnCloseWindow( wxCloseEvent &event )
{
// if ! saved changes -> return
if (!Discard()) return;
Destroy();
}
@ -150,7 +220,7 @@ MyApp::MyApp()
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame( NULL, -1, "SuperApp", wxPoint(20,20), wxSize(500,340) );
MyFrame *frame = new MyFrame( NULL, -1, "wxEdit", wxPoint(20,20), wxSize(500,340) );
frame->Show( TRUE );
return TRUE;

View File

@ -29,6 +29,15 @@
#define ID_SAVEAS 203
#define ID_QUIT 204
#define ID_COPY 300
#define ID_CUT 301
#define ID_PASTE 302
#define ID_DELETE 303
#define ID_LAST_1 401
#define ID_LAST_2 402
#define ID_LAST_3 403
//----------------------------------------------------------------------------
// MyFrame
//----------------------------------------------------------------------------
@ -55,6 +64,19 @@ private:
void OnSave( wxCommandEvent &event );
void OnSaveAs( wxCommandEvent &event );
void OnQuit( wxCommandEvent &event );
void OnCopy( wxCommandEvent &event );
void OnCut( wxCommandEvent &event );
void OnPaste( wxCommandEvent &event );
void OnDelete( wxCommandEvent &event );
void OnLast1( wxCommandEvent &event );
void OnLast2( wxCommandEvent &event );
void OnLast3( wxCommandEvent &event );
bool Save();
bool Discard();
void OnCloseWindow( wxCloseEvent &event );
private: