]>
Commit | Line | Data |
---|---|---|
9ce192d4 RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: stctest.cpp | |
3 | // Purpose: sample of using wxStyledTextCtrl | |
4 | // Author: Robin Dunn | |
5 | // Modified by: | |
6 | // Created: 3-Feb-2000 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 2000 by Total Control Software | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
ab7ce33c | 12 | #if defined(__GNUG__) && !defined(__APPLE__) |
9ce192d4 RD |
13 | #pragma implementation "stctest.cpp" |
14 | #pragma interface "stctest.cpp" | |
15 | #endif | |
16 | ||
17 | // For compilers that support precompilation, includes "wx/wx.h". | |
18 | #include "wx/wxprec.h" | |
19 | ||
20 | #ifdef __BORLANDC__ | |
21 | #pragma hdrstop | |
22 | #endif | |
23 | ||
24 | // for all others, include the necessary headers (this file is usually all you | |
25 | // need because it includes almost all "standard" wxWindows headers | |
26 | #ifndef WX_PRECOMP | |
27 | #include "wx/wx.h" | |
28 | #endif | |
29 | ||
30 | #include <wx/wfstream.h> | |
31 | ||
32 | #include <wx/stc/stc.h> | |
33 | ||
34 | //---------------------------------------------------------------------- | |
35 | ||
36 | class MyApp : public wxApp | |
37 | { | |
38 | public: | |
39 | virtual bool OnInit(); | |
40 | }; | |
41 | ||
42 | //---------------------------------------------------------------------- | |
43 | ||
44 | // Define a new frame type: this is going to be our main frame | |
45 | class MyFrame : public wxFrame | |
46 | { | |
47 | public: | |
48 | MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); | |
49 | ||
50 | void OnQuit(wxCommandEvent& event); | |
51 | void OnAbout(wxCommandEvent& event); | |
9ce192d4 RD |
52 | |
53 | private: | |
54 | wxStyledTextCtrl* ed; | |
55 | ||
56 | DECLARE_EVENT_TABLE() | |
57 | }; | |
58 | ||
59 | ||
60 | // IDs for the controls and the menu commands | |
61 | enum | |
62 | { | |
63 | // menu items | |
64 | ID_Quit = 1, | |
65 | ID_About, | |
66 | ID_ED | |
67 | }; | |
68 | ||
69 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
70 | EVT_MENU (ID_Quit, MyFrame::OnQuit) | |
71 | EVT_MENU (ID_About, MyFrame::OnAbout) | |
9ce192d4 RD |
72 | END_EVENT_TABLE() |
73 | ||
74 | IMPLEMENT_APP(MyApp) | |
75 | ||
76 | //---------------------------------------------------------------------- | |
77 | // `Main program' equivalent: the program execution "starts" here | |
78 | ||
79 | bool MyApp::OnInit() | |
80 | { | |
695c21b1 | 81 | MyFrame *frame = new MyFrame(_T("Testing wxStyledTextCtrl"), |
9ce192d4 RD |
82 | wxPoint(5, 5), wxSize(400, 600)); |
83 | ||
84 | frame->Show(TRUE); | |
85 | return TRUE; | |
86 | } | |
87 | ||
88 | //---------------------------------------------------------------------- | |
89 | ||
90 | // frame constructor | |
91 | MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) | |
92 | : wxFrame((wxFrame *)NULL, -1, title, pos, size) | |
93 | { | |
94 | #ifdef __WXMAC__ | |
95 | // we need this in order to allow the about menu relocation, since ABOUT is | |
96 | // not the default id of the about menu | |
97 | wxApp::s_macAboutMenuItemId = ID_About; | |
98 | #endif | |
99 | ||
100 | ||
101 | // create a menu bar | |
695c21b1 | 102 | wxMenu *menuFile = new wxMenu(wxEmptyString, wxMENU_TEAROFF); |
9ce192d4 RD |
103 | |
104 | // the "About" item should be in the help menu | |
105 | wxMenu *helpMenu = new wxMenu; | |
695c21b1 | 106 | helpMenu->Append(ID_About, _T("&About...\tCtrl-A"), _T("Show about dialog")); |
9ce192d4 | 107 | |
695c21b1 | 108 | menuFile->Append(ID_Quit, _T("E&xit\tAlt-X"), _T("Quit this program")); |
9ce192d4 RD |
109 | |
110 | // now append the freshly created menu to the menu bar... | |
111 | wxMenuBar *menuBar = new wxMenuBar(); | |
695c21b1 JS |
112 | menuBar->Append(menuFile, _T("&File")); |
113 | menuBar->Append(helpMenu, _T("&Help")); | |
9ce192d4 RD |
114 | |
115 | // ... and attach this menu bar to the frame | |
116 | SetMenuBar(menuBar); | |
117 | ||
118 | #if wxUSE_STATUSBAR | |
119 | CreateStatusBar(2); | |
695c21b1 | 120 | SetStatusText(_T("Testing wxStyledTextCtrl")); |
9ce192d4 RD |
121 | #endif // wxUSE_STATUSBAR |
122 | ||
123 | ||
124 | //---------------------------------------- | |
125 | // Setup the editor | |
126 | ed = new wxStyledTextCtrl(this, ID_ED); | |
127 | ||
128 | // Default font | |
c19d0121 | 129 | wxFont font(10, wxMODERN, wxNORMAL, wxNORMAL); |
9ce192d4 RD |
130 | ed->StyleSetFont(wxSTC_STYLE_DEFAULT, font); |
131 | ed->StyleClearAll(); | |
132 | ||
133 | ed->StyleSetForeground(0, wxColour(0x80, 0x80, 0x80)); | |
134 | ed->StyleSetForeground(1, wxColour(0x00, 0x7f, 0x00)); | |
135 | //ed->StyleSetForeground(2, wxColour(0x00, 0x7f, 0x00)); | |
136 | ed->StyleSetForeground(3, wxColour(0x7f, 0x7f, 0x7f)); | |
137 | ed->StyleSetForeground(4, wxColour(0x00, 0x7f, 0x7f)); | |
138 | ed->StyleSetForeground(5, wxColour(0x00, 0x00, 0x7f)); | |
139 | ed->StyleSetForeground(6, wxColour(0x7f, 0x00, 0x7f)); | |
140 | ed->StyleSetForeground(7, wxColour(0x7f, 0x00, 0x7f)); | |
141 | ed->StyleSetForeground(8, wxColour(0x00, 0x7f, 0x7f)); | |
142 | ed->StyleSetForeground(9, wxColour(0x7f, 0x7f, 0x7f)); | |
143 | ed->StyleSetForeground(10, wxColour(0x00, 0x00, 0x00)); | |
144 | ed->StyleSetForeground(11, wxColour(0x00, 0x00, 0x00)); | |
145 | ed->StyleSetBold(5, TRUE); | |
146 | ed->StyleSetBold(10, TRUE); | |
147 | ||
148 | #ifdef __WXMSW__ | |
695c21b1 | 149 | ed->StyleSetSpec(2, _T("fore:#007f00,bold,face:Arial,size:9")); |
9ce192d4 | 150 | #else |
695c21b1 | 151 | ed->StyleSetSpec(2, _T("fore:#007f00,bold,face:Helvetica,size:9")); |
9ce192d4 RD |
152 | #endif |
153 | ||
154 | // give it some text to play with | |
9ce192d4 | 155 | wxString st; |
695c21b1 JS |
156 | wxFileInputStream stream(wxT("stctest.cpp")); |
157 | size_t sz = stream.GetSize(); | |
158 | char* buf = new char[sz + 1]; | |
159 | stream.Read((void*) buf, stream.GetSize()); | |
160 | buf[sz] = 0; | |
161 | st = wxString::FromAscii(buf); | |
162 | delete[] buf; | |
9ce192d4 RD |
163 | |
164 | ed->InsertText(0, st); | |
165 | ed->EmptyUndoBuffer(); | |
166 | ||
167 | ed->SetLexer(wxSTC_LEX_CPP); | |
4370573a | 168 | ed->SetKeyWords(0, |
695c21b1 JS |
169 | _T("asm auto bool break case catch char class const \ |
170 | const_cast continue default delete do double \ | |
171 | dynamic_cast else enum explicit export extern \ | |
172 | false float for friend goto if inline int long \ | |
173 | mutable namespace new operator private protected \ | |
174 | public register reinterpret_cast return short signed \ | |
175 | sizeof static static_cast struct switch template this \ | |
176 | throw true try typedef typeid typename union unsigned \ | |
177 | using virtual void volatile wchar_t while")); | |
9ce192d4 RD |
178 | |
179 | } | |
180 | ||
181 | ||
182 | // event handlers | |
183 | ||
9ce192d4 RD |
184 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) |
185 | { | |
186 | // TRUE is to force the frame to close | |
187 | Close(TRUE); | |
188 | } | |
189 | ||
190 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) | |
191 | { | |
192 | wxString msg; | |
193 | msg.Printf( _T("Testing wxStyledTextCtrl...\n")); | |
194 | ||
695c21b1 | 195 | wxMessageBox(msg, _T("About This Test"), wxOK | wxICON_INFORMATION, this); |
9ce192d4 | 196 | } |