]> git.saurik.com Git - wxWidgets.git/blame_incremental - mobile/wxedit/wxedit.cpp
removed code (not necessary anymore)
[wxWidgets.git] / mobile / wxedit / wxedit.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: wxedit.cpp
3// Author: Robert Roebling
4// Created: 04/07/02
5// Copyright:
6/////////////////////////////////////////////////////////////////////////////
7
8#ifdef __GNUG__
9 #pragma implementation "wxedit.cpp"
10#endif
11
12// For compilers that support precompilation
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16 #pragma hdrstop
17#endif
18
19#include "wx/filename.h"
20
21// Include private headers
22#include "wxedit.h"
23
24//------------------------------------------------------------------------------
25// MyFrame
26//------------------------------------------------------------------------------
27
28BEGIN_EVENT_TABLE(MyFrame,wxFrame)
29 EVT_MENU(ID_ABOUT, MyFrame::OnAbout)
30
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)
36
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)
41
42 EVT_MENU(ID_LAST_1, MyFrame::OnLast1)
43 EVT_MENU(ID_LAST_2, MyFrame::OnLast2)
44 EVT_MENU(ID_LAST_3, MyFrame::OnLast3)
45
46 EVT_CLOSE(MyFrame::OnCloseWindow)
47END_EVENT_TABLE()
48
49MyFrame::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 )
52{
53 CreateMyMenuBar();
54
55 CreateStatusBar(1);
56 SetStatusText( "Welcome!" );
57
58 m_text = new wxTextCtrl( this, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
59}
60
61void MyFrame::CreateMyMenuBar()
62{
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" );
72
73 wxMenuBar *menu_bar = new wxMenuBar();
74 menu_bar->Append( file_menu, "File" );
75
76 SetMenuBar( menu_bar );
77}
78
79void MyFrame::OnCopy( wxCommandEvent &event )
80{
81}
82
83void MyFrame::OnCut( wxCommandEvent &event )
84{
85}
86
87void MyFrame::OnPaste( wxCommandEvent &event )
88{
89}
90
91void MyFrame::OnDelete( wxCommandEvent &event )
92{
93}
94
95void MyFrame::OnLast1( wxCommandEvent &event )
96{
97}
98
99void MyFrame::OnLast2( wxCommandEvent &event )
100{
101}
102
103void MyFrame::OnLast3( wxCommandEvent &event )
104{
105}
106
107void MyFrame::OnNew( wxCommandEvent &event )
108{
109 if (!Discard()) return;
110
111 m_text->Clear();
112}
113
114void MyFrame::OnOpen( wxCommandEvent &event )
115{
116 wxFileDialog dialog( this, "Open text", "", "",
117 "Text file (*.txt)|*.txt|"
118 "Any file (*)|*",
119 wxOPEN|wxFILE_MUST_EXIST );
120 if (dialog.ShowModal() == wxID_OK)
121 {
122 m_text->Clear();
123
124#ifdef __WXX11__
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"))
131 {
132 m_text->SetLanguage( wxSOURCE_LANG_CPP );
133 }
134 else
135 if (fname.GetExt() == "py")
136 {
137 m_text->SetLanguage( wxSOURCE_LANG_PYTHON );
138 }
139 else
140 if ((fname.GetExt() == "pl") ||
141 (fname.GetExt() == "pm"))
142 {
143 m_text->SetLanguage( wxSOURCE_LANG_PYTHON );
144 }
145 else
146 {
147 m_text->SetLanguage( wxSOURCE_LANG_NONE );
148 }
149#endif
150
151 m_text->LoadFile( dialog.GetPath() );
152 }
153}
154
155void MyFrame::OnSave( wxCommandEvent &event )
156{
157}
158
159void MyFrame::OnSaveAs( wxCommandEvent &event )
160{
161}
162
163void MyFrame::OnAbout( wxCommandEvent &event )
164{
165 wxMessageDialog dialog( this, "Welcome to wxEdit\n(C)opyright Robert Roebling",
166 "About wxEdit", wxOK|wxICON_INFORMATION );
167 dialog.ShowModal();
168}
169
170void MyFrame::OnQuit( wxCommandEvent &event )
171{
172 Close( TRUE );
173}
174
175bool MyFrame::Save()
176{
177 m_text->SaveFile();
178
179 return TRUE;
180}
181
182bool MyFrame::Discard()
183{
184 if (m_text->IsModified())
185 {
186 wxMessageDialog dialog( this, "Text has been modified! Save?",
187 "wxEdit", wxYES_NO|wxCANCEL|wxICON_EXCLAMATION );
188
189 int ret = dialog.ShowModal();
190
191 if (ret == wxID_CANCEL)
192 return FALSE;
193
194 if (ret == wxID_YES)
195 {
196 if (!Save())
197 return FALSE;
198 }
199 }
200
201 return TRUE;
202}
203
204void MyFrame::OnCloseWindow( wxCloseEvent &event )
205{
206 if (!Discard()) return;
207
208 Destroy();
209}
210
211//------------------------------------------------------------------------------
212// MyApp
213//------------------------------------------------------------------------------
214
215IMPLEMENT_APP(MyApp)
216
217MyApp::MyApp()
218{
219}
220
221bool MyApp::OnInit()
222{
223 MyFrame *frame = new MyFrame( NULL, -1, "wxEdit", wxPoint(20,20), wxSize(500,340) );
224 frame->Show( TRUE );
225
226 return TRUE;
227}
228
229int MyApp::OnExit()
230{
231 return 0;
232}
233