1.
Owner drawn menu items (sort of)

2.
Match/Compile time


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24961 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Ryan Norton
2003-12-21 22:03:12 +00:00
parent 81e6573009
commit acee956c6d
2 changed files with 74 additions and 38 deletions

View File

@@ -21,7 +21,7 @@ Select your options from the Options menu -
Most of them are documented in the wxRegEx Most of them are documented in the wxRegEx
class docs in wxWindows. class docs in wxWindows.
Test Compile - Adds compile to the match time Test Compile/Match - Adds compile/match to the match time
speed test (i.e. it compiles and matches speed test (i.e. it compiles and matches
the number of times that are specified the number of times that are specified
in the iterations field, otherwise in the iterations field, otherwise

View File

@@ -1,6 +1,6 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: regextest.cpp // Name: regextest.cpp
// Purpose: Application to test regular expression (wxRegEx) // Purpose: Test regex libs and some gui components
// Author: Ryan Norton // Author: Ryan Norton
// Modified by: // Modified by:
// RCS-ID: $Id$ // RCS-ID: $Id$
@@ -90,10 +90,10 @@
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// MyDialog // MyFrame
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
class MyDialog : public wxFrame class MyFrame : public wxFrame
{ {
public: public:
@@ -113,11 +113,36 @@ public:
NewLineID, NewLineID,
NotBolID, NotBolID,
NotEolID, NotEolID,
CompID CompID,
MatchID
}; };
MyDialog() : wxFrame( NULL, -1, _("regextest - wxRegEx Testing App"), void AddMenuItem(wxMenu* pMenu, int nID = wxID_SEPARATOR, const wxChar* szTitle = _(""),
const wxChar* szToolTip = _(""))
{
wxMenuItem* pItem;
if (nID == wxID_SEPARATOR)
pItem = new wxMenuItem (NULL, wxID_SEPARATOR, szTitle, szToolTip, wxITEM_SEPARATOR);
else
pItem = new wxMenuItem (NULL, nID, szTitle, szToolTip, wxITEM_CHECK);
pItem->SetBackgroundColour(wxColour(115, 113, 115));
pItem->SetTextColour(*wxBLACK);
pMenu->Append(pItem);
}
#if defined( __WXMSW__ ) || defined( __WXMAC__ )
void OnContextMenu(wxContextMenuEvent& event)
{ PopupMenu(OptionsMenu, ScreenToClient(event.GetPosition())); }
#else
void OnRightUp(wxMouseEvent& event)
{ PopupMenu(OptionsMenu, event.GetPosition()); }
#endif
MyFrame() : wxFrame( NULL, -1, _("regextest - wxRegEx Testing App"),
wxPoint(20,20), wxSize(300,400), wxDEFAULT_FRAME_STYLE | wxTAB_TRAVERSAL ) wxPoint(20,20), wxSize(300,400), wxDEFAULT_FRAME_STYLE | wxTAB_TRAVERSAL )
{ {
//Set the background to something light gray-ish //Set the background to something light gray-ish
@@ -131,20 +156,23 @@ public:
OptionsMenu = new wxMenu; OptionsMenu = new wxMenu;
wxMenu *HelpMenu = new wxMenu; wxMenu *HelpMenu = new wxMenu;
FileMenu->Append(wxID_EXIT, _T("&Exit"), _("Quit this program")); AddMenuItem(FileMenu, wxID_EXIT, _("&Exit"), _("Quit this program"));
AddMenuItem(OptionsMenu, ExtendedID, _T("wxRE_EXTENDED"), _("Extended Regular Expressions?"));
AddMenuItem(OptionsMenu, ICaseID, _T("wxRE_ICASE"), _("Enable case-insensitive matching?"));
AddMenuItem(OptionsMenu, NewLineID, _T("wxRE_NEWLINE"), _("Treat \n as special?"));
AddMenuItem(OptionsMenu);
AddMenuItem(OptionsMenu, NotBolID, _T("wxRE_NOTBOL"), _("Use functionality of ^ character?"));
AddMenuItem(OptionsMenu, NotEolID, _T("wxRE_NOTEOL"), _("Use functionality of $ character?"));
AddMenuItem(OptionsMenu);
AddMenuItem(OptionsMenu);
AddMenuItem(OptionsMenu, CompID, _("Test Compile"), _("Added Compiling to Match Time?"));
AddMenuItem(OptionsMenu, MatchID, _("Test Match"), _("Added Matching to Match Time?"));
AddMenuItem(HelpMenu, wxID_ABOUT, _T("&About...\tF1"), _("Show about dialog"));
OptionsMenu->AppendCheckItem(ExtendedID, _T("wxRE_EXTENDED"), _("Extended Regular Expressions?"));
OptionsMenu->AppendCheckItem(ICaseID, _T("wxRE_ICASE"), _("Enable case-insensitive matching?"));
OptionsMenu->AppendCheckItem(NewLineID, _T("wxRE_NEWLINE"), _("Treat \n as special?"));
OptionsMenu->AppendSeparator();
OptionsMenu->AppendCheckItem(NotBolID, _T("wxRE_NOTBOL"), _("Use functionality of ^ character?"));
OptionsMenu->AppendCheckItem(NotEolID, _T("wxRE_NOTEOL"), _("Use functionality of $ character?"));
OptionsMenu->AppendSeparator();
OptionsMenu->AppendSeparator();
OptionsMenu->AppendCheckItem(CompID, _T("Test Compile"), _("Added Compiling to Match Time?"));
OptionsMenu->Check(ExtendedID, true); OptionsMenu->Check(ExtendedID, true);
OptionsMenu->Check(MatchID, true);
HelpMenu->Append(wxID_ABOUT, _T("&About...\tF1"), _("Show about dialog"));
wxMenuBar *MenuBar = new wxMenuBar(); wxMenuBar *MenuBar = new wxMenuBar();
MenuBar->Append(FileMenu, _T("&File")); MenuBar->Append(FileMenu, _T("&File"));
@@ -323,10 +351,9 @@ public:
for(i = 0; i < n; ++i) for(i = 0; i < n; ++i)
{ {
Regex.Compile(szPattern, nCompileFlags); Regex.Compile(szPattern, nCompileFlags);
Regex.Matches(szSearch, nMatchFlags);
} }
} }
else if (OptionsMenu->IsChecked(MatchID))
{ {
for(i = 0; i < n; ++i) for(i = 0; i < n; ++i)
{ {
@@ -375,10 +402,9 @@ public:
for(i = 0; i < n; ++i) for(i = 0; i < n; ++i)
{ {
Re.Comp(szPattern, nCompileFlags2); Re.Comp(szPattern, nCompileFlags2);
Re.Exec(szSearch, nMatchFlags2);
} }
} }
else if (OptionsMenu->IsChecked(MatchID))
{ {
for(i = 0; i < n; ++i) for(i = 0; i < n; ++i)
{ {
@@ -417,11 +443,15 @@ public:
{ {
for(i = 0; i < n; ++i) for(i = 0; i < n; ++i)
{ {
//Supposively GRETA doesn't compile, but
//it's clear that it slows performance greatly
//when creating a rpattern object,
//so one can only surmize that it performs
//some kind of optimizations in the constructor
Greta = rpattern(stdszPattern,EXTENDED,MODE_MIXED); Greta = rpattern(stdszPattern,EXTENDED,MODE_MIXED);
Greta.match(stdszSearch, r);
} }
} }
else if (OptionsMenu->IsChecked(MatchID))
{ {
for(i = 0; i < n; ++i) for(i = 0; i < n; ++i)
{ {
@@ -466,15 +496,15 @@ public:
dwStartTime4 = clock(); dwStartTime4 = clock();
if (OptionsMenu->IsChecked(CompID)) if (OptionsMenu->IsChecked(CompID))
{ {
for(i = 0; i < n; ++i) for(i = 0; i < n; ++i)
{ {
pPcre = pcre_compile(szPattern, nCompileFlags4, &szError, &nErrOff, 0); pPcre = pcre_compile(szPattern, nCompileFlags4, &szError, &nErrOff, 0);
pcre_exec(pPcre, 0, szSearch, szSearch.Length(), 0, 0, m, msize);
} }
} }
else if (OptionsMenu->IsChecked(MatchID))
{ {
for(i = 0; i < n; ++i) for(i = 0; i < n; ++i)
{ {
@@ -512,18 +542,24 @@ public:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
BEGIN_EVENT_TABLE(MyDialog, wxFrame) BEGIN_EVENT_TABLE(MyFrame, wxFrame)
//menu //menu
EVT_MENU(wxID_EXIT, MyDialog::OnQuit) EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
EVT_MENU(wxID_ABOUT, MyDialog::OnAbout) EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
//text //text
EVT_TEXT_ENTER(MyDialog::PatternTextID, MyDialog::OnMatch) EVT_TEXT_ENTER(MyFrame::PatternTextID, MyFrame::OnMatch)
EVT_TEXT_ENTER(MyDialog::SearchTextID, MyDialog::OnMatch) EVT_TEXT_ENTER(MyFrame::SearchTextID, MyFrame::OnMatch)
//button //button
EVT_BUTTON(MyDialog::OkButtonID, MyDialog::OnMatch) EVT_BUTTON(MyFrame::OkButtonID, MyFrame::OnMatch)
#if defined( __WXMSW__ ) || defined( __WXMAC__ )
EVT_CONTEXT_MENU(MyFrame::OnContextMenu)
#else
EVT_RIGHT_UP(MyFrame::OnRightUp)
#endif
END_EVENT_TABLE() END_EVENT_TABLE()
@@ -536,7 +572,7 @@ class MyApp : public wxApp
public: public:
bool OnInit() bool OnInit()
{ {
MyDialog* dialog = new MyDialog(); MyFrame* dialog = new MyFrame();
dialog->Show(); dialog->Show();
return true; return true;
} }