]> git.saurik.com Git - wxWidgets.git/blob - mobile/wxedit/wxedit.cpp
98c5d0bbee2d3e6cd54309c348ba47ec143d8f54
[wxWidgets.git] / mobile / wxedit / wxedit.cpp
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
28 BEGIN_EVENT_TABLE(MyFrame,wxFrame)
29 EVT_MENU(ID_ABOUT, MyFrame::OnAbout)
30 EVT_MENU(ID_NEW, MyFrame::OnNew)
31 EVT_MENU(ID_OPEN, MyFrame::OnOpen)
32 EVT_MENU(ID_SAVE, MyFrame::OnSave)
33 EVT_MENU(ID_SAVEAS, MyFrame::OnSaveAs)
34 EVT_MENU(ID_QUIT, MyFrame::OnQuit)
35 EVT_CLOSE(MyFrame::OnCloseWindow)
36 END_EVENT_TABLE()
37
38 MyFrame::MyFrame( wxWindow *parent, wxWindowID id, const wxString &title,
39 const wxPoint &position, const wxSize& size, long style ) :
40 wxFrame( parent, id, title, position, size, style )
41 {
42 CreateMyMenuBar();
43
44 CreateStatusBar(1);
45 SetStatusText( "Welcome!" );
46
47 m_text = new wxTextCtrl( this, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
48 }
49
50 void MyFrame::CreateMyMenuBar()
51 {
52 wxMenu *file_menu = new wxMenu;
53 file_menu->Append( ID_ABOUT, "About...", "Program info" );
54 file_menu->AppendSeparator();
55 file_menu->Append( ID_NEW, "New...", "New text" );
56 file_menu->Append( ID_OPEN, "Open...", "Open text" );
57 file_menu->Append( ID_SAVE, "Save", "Save text" );
58 file_menu->Append( ID_SAVEAS, "Save as...", "Save text as..." );
59 file_menu->AppendSeparator();
60 file_menu->Append( ID_QUIT, "Quit...", "Quit program" );
61
62 wxMenuBar *menu_bar = new wxMenuBar();
63 menu_bar->Append( file_menu, "File" );
64
65 SetMenuBar( menu_bar );
66 }
67
68 void MyFrame::OnNew( wxCommandEvent &event )
69 {
70 m_text->Clear();
71 }
72
73 void MyFrame::OnOpen( wxCommandEvent &event )
74 {
75 wxFileDialog dialog( this, "Open text", "", "",
76 "Text file (*.txt)|*.txt|"
77 "Any file (*)|*",
78 wxOPEN|wxFILE_MUST_EXIST );
79 if (dialog.ShowModal() == wxID_OK)
80 {
81 m_text->Clear();
82
83 #ifdef __WXX11__
84 wxFileName fname( dialog.GetPath() );
85 if ((fname.GetExt() == "cpp") ||
86 (fname.GetExt() == "c") ||
87 (fname.GetExt() == "h") ||
88 (fname.GetExt() == "cxx") ||
89 (fname.GetExt() == "hxx"))
90 {
91 m_text->SetLanguage( wxSOURCE_LANG_CPP );
92 }
93 else
94 if (fname.GetExt() == "py")
95 {
96 m_text->SetLanguage( wxSOURCE_LANG_PYTHON );
97 }
98 else
99 if ((fname.GetExt() == "pl") ||
100 (fname.GetExt() == "pm"))
101 {
102 m_text->SetLanguage( wxSOURCE_LANG_PYTHON );
103 }
104 else
105 {
106 m_text->SetLanguage( wxSOURCE_LANG_NONE );
107 }
108 #endif
109
110 m_text->LoadFile( dialog.GetPath() );
111 }
112 }
113
114 void MyFrame::OnSave( wxCommandEvent &event )
115 {
116 }
117
118 void MyFrame::OnSaveAs( wxCommandEvent &event )
119 {
120 }
121
122 void MyFrame::OnAbout( wxCommandEvent &event )
123 {
124 wxMessageDialog dialog( this, "Welcome to SuperApp 1.0\n(C)opyright Joe Hacker",
125 "About SuperApp", wxOK|wxICON_INFORMATION );
126 dialog.ShowModal();
127 }
128
129 void MyFrame::OnQuit( wxCommandEvent &event )
130 {
131 Close( TRUE );
132 }
133
134 void MyFrame::OnCloseWindow( wxCloseEvent &event )
135 {
136 // if ! saved changes -> return
137
138 Destroy();
139 }
140
141 //------------------------------------------------------------------------------
142 // MyApp
143 //------------------------------------------------------------------------------
144
145 IMPLEMENT_APP(MyApp)
146
147 MyApp::MyApp()
148 {
149 }
150
151 bool MyApp::OnInit()
152 {
153 MyFrame *frame = new MyFrame( NULL, -1, "SuperApp", wxPoint(20,20), wxSize(500,340) );
154 frame->Show( TRUE );
155
156 return TRUE;
157 }
158
159 int MyApp::OnExit()
160 {
161 return 0;
162 }
163