]>
git.saurik.com Git - wxWidgets.git/blob - samples/stc/stctest.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: sample of using wxStyledTextCtrl
8 // Copyright: (c) 2000 by Total Control Software
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(__APPLE__)
13 #pragma implementation "stctest.cpp"
14 #pragma interface "stctest.cpp"
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
24 // for all others, include the necessary headers (this file is usually all you
25 // need because it includes almost all "standard" wxWindows headers
30 #include <wx/wfstream.h>
32 #include <wx/stc/stc.h>
34 //----------------------------------------------------------------------
36 class MyApp
: public wxApp
39 virtual bool OnInit();
42 //----------------------------------------------------------------------
44 // Define a new frame type: this is going to be our main frame
45 class MyFrame
: public wxFrame
48 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
50 void OnQuit(wxCommandEvent
& event
);
51 void OnAbout(wxCommandEvent
& event
);
60 // IDs for the controls and the menu commands
69 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
70 EVT_MENU (ID_Quit
, MyFrame::OnQuit
)
71 EVT_MENU (ID_About
, MyFrame::OnAbout
)
76 //----------------------------------------------------------------------
77 // `Main program' equivalent: the program execution "starts" here
81 MyFrame
*frame
= new MyFrame("Testing wxStyledTextCtrl",
82 wxPoint(5, 5), wxSize(400, 600));
88 //----------------------------------------------------------------------
91 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
92 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
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
;
102 wxMenu
*menuFile
= new wxMenu("", wxMENU_TEAROFF
);
104 // the "About" item should be in the help menu
105 wxMenu
*helpMenu
= new wxMenu
;
106 helpMenu
->Append(ID_About
, "&About...\tCtrl-A", "Show about dialog");
108 menuFile
->Append(ID_Quit
, "E&xit\tAlt-X", "Quit this program");
110 // now append the freshly created menu to the menu bar...
111 wxMenuBar
*menuBar
= new wxMenuBar();
112 menuBar
->Append(menuFile
, "&File");
113 menuBar
->Append(helpMenu
, "&Help");
115 // ... and attach this menu bar to the frame
120 SetStatusText("Testing wxStyledTextCtrl");
121 #endif // wxUSE_STATUSBAR
124 //----------------------------------------
126 ed
= new wxStyledTextCtrl(this, ID_ED
);
129 wxFont
font(10, wxMODERN
, wxNORMAL
, wxNORMAL
);
130 ed
->StyleSetFont(wxSTC_STYLE_DEFAULT
, font
);
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
);
149 ed
->StyleSetSpec(2, "fore:#007f00,bold,face:Arial,size:9");
151 ed
->StyleSetSpec(2, "fore:#007f00,bold,face:Helvetica,size:9");
154 // give it some text to play with
155 wxFile
file("stctest.cpp");
158 char* buff
= st
.GetWriteBuf(file
.Length());
159 file
.Read(buff
, file
.Length());
162 ed
->InsertText(0, st
);
163 ed
->EmptyUndoBuffer();
165 ed
->SetLexer(wxSTC_LEX_CPP
);
167 "asm auto bool break case catch char class const "
168 "const_cast continue default delete do double "
169 "dynamic_cast else enum explicit export extern "
170 "false float for friend goto if inline int long "
171 "mutable namespace new operator private protected "
172 "public register reinterpret_cast return short signed "
173 "sizeof static static_cast struct switch template this "
174 "throw true try typedef typeid typename union unsigned "
175 "using virtual void volatile wchar_t while");
182 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
184 // TRUE is to force the frame to close
188 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
191 msg
.Printf( _T("Testing wxStyledTextCtrl...\n"));
193 wxMessageBox(msg
, "About This Test", wxOK
| wxICON_INFORMATION
, this);