]>
git.saurik.com Git - wxWidgets.git/blob - mobile/wxedit/wxedit.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Author: Robert Roebling
6 /////////////////////////////////////////////////////////////////////////////
9 #pragma implementation "wxedit.cpp"
12 // For compilers that support precompilation
13 #include "wx/wxprec.h"
19 #include "wx/filename.h"
21 // Include private headers
24 //------------------------------------------------------------------------------
26 //------------------------------------------------------------------------------
28 BEGIN_EVENT_TABLE(MyFrame
,wxFrame
)
29 EVT_MENU(ID_ABOUT
, MyFrame::OnAbout
)
31 EVT_MENU(ID_NEW
, MyFrame::OnNew
)
32 EVT_MENU(ID_OPEN
, MyFrame::OnOpen
)
33 EVT_MENU(ID_SAVE
, MyFrame::OnSave
)
34 EVT_MENU(ID_SAVEAS
, MyFrame::OnSaveAs
)
35 EVT_MENU(ID_QUIT
, MyFrame::OnQuit
)
37 EVT_MENU(ID_COPY
, MyFrame::OnCopy
)
38 EVT_MENU(ID_CUT
, MyFrame::OnCut
)
39 EVT_MENU(ID_PASTE
, MyFrame::OnPaste
)
40 EVT_MENU(ID_DELETE
, MyFrame::OnDelete
)
42 EVT_MENU(ID_LAST_1
, MyFrame::OnLast1
)
43 EVT_MENU(ID_LAST_2
, MyFrame::OnLast2
)
44 EVT_MENU(ID_LAST_3
, MyFrame::OnLast3
)
46 EVT_CLOSE(MyFrame::OnCloseWindow
)
49 MyFrame::MyFrame( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
50 const wxPoint
&position
, const wxSize
& size
, long style
) :
51 wxFrame( parent
, id
, title
, position
, size
, style
)
56 SetStatusText( "Welcome!" );
58 m_text
= new wxTextCtrl( this, -1, "", wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE
);
61 void MyFrame::CreateMyMenuBar()
63 wxMenu
*file_menu
= new wxMenu
;
64 file_menu
->Append( ID_ABOUT
, "About...", "Program info" );
65 file_menu
->AppendSeparator();
66 file_menu
->Append( ID_NEW
, "New...", "New text" );
67 file_menu
->Append( ID_OPEN
, "Open...", "Open text" );
68 file_menu
->Append( ID_SAVE
, "Save", "Save text" );
69 file_menu
->Append( ID_SAVEAS
, "Save as...", "Save text as..." );
70 file_menu
->AppendSeparator();
71 file_menu
->Append( ID_QUIT
, "Quit...", "Quit program" );
73 wxMenuBar
*menu_bar
= new wxMenuBar();
74 menu_bar
->Append( file_menu
, "File" );
76 SetMenuBar( menu_bar
);
79 void MyFrame::OnCopy( wxCommandEvent
&event
)
83 void MyFrame::OnCut( wxCommandEvent
&event
)
87 void MyFrame::OnPaste( wxCommandEvent
&event
)
91 void MyFrame::OnDelete( wxCommandEvent
&event
)
95 void MyFrame::OnLast1( wxCommandEvent
&event
)
99 void MyFrame::OnLast2( wxCommandEvent
&event
)
103 void MyFrame::OnLast3( wxCommandEvent
&event
)
107 void MyFrame::OnNew( wxCommandEvent
&event
)
109 if (!Discard()) return;
114 void MyFrame::OnOpen( wxCommandEvent
&event
)
116 wxFileDialog
dialog( this, "Open text", "", "",
117 "Text file (*.txt)|*.txt|"
119 wxOPEN
|wxFILE_MUST_EXIST
);
120 if (dialog
.ShowModal() == wxID_OK
)
125 wxFileName
fname( dialog
.GetPath() );
126 if ((fname
.GetExt() == "cpp") ||
127 (fname
.GetExt() == "c") ||
128 (fname
.GetExt() == "h") ||
129 (fname
.GetExt() == "cxx") ||
130 (fname
.GetExt() == "hxx"))
132 m_text
->SetLanguage( wxSOURCE_LANG_CPP
);
135 if (fname
.GetExt() == "py")
137 m_text
->SetLanguage( wxSOURCE_LANG_PYTHON
);
140 if ((fname
.GetExt() == "pl") ||
141 (fname
.GetExt() == "pm"))
143 m_text
->SetLanguage( wxSOURCE_LANG_PYTHON
);
147 m_text
->SetLanguage( wxSOURCE_LANG_NONE
);
151 m_text
->LoadFile( dialog
.GetPath() );
155 void MyFrame::OnSave( wxCommandEvent
&event
)
159 void MyFrame::OnSaveAs( wxCommandEvent
&event
)
163 void MyFrame::OnAbout( wxCommandEvent
&event
)
165 wxMessageDialog
dialog( this, "Welcome to wxEdit\n(C)opyright Robert Roebling",
166 "About wxEdit", wxOK
|wxICON_INFORMATION
);
170 void MyFrame::OnQuit( wxCommandEvent
&event
)
182 bool MyFrame::Discard()
184 if (m_text
->IsModified())
186 wxMessageDialog
dialog( this, "Text has been modified! Save?",
187 "wxEdit", wxYES_NO
|wxCANCEL
|wxICON_EXCLAMATION
);
189 int ret
= dialog
.ShowModal();
191 if (ret
== wxID_CANCEL
)
204 void MyFrame::OnCloseWindow( wxCloseEvent
&event
)
206 if (!Discard()) return;
211 //------------------------------------------------------------------------------
213 //------------------------------------------------------------------------------
223 MyFrame
*frame
= new MyFrame( NULL
, -1, "wxEdit", wxPoint(20,20), wxSize(500,340) );