accels for menu commands
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4068 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -10,11 +10,8 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO:
|
TODO: use worker threads to update progress controls instead of writing
|
||||||
|
messages - it will be more visual
|
||||||
1. show how SetPriority() works.
|
|
||||||
2. use worker threads to update progress controls instead of writing
|
|
||||||
messages - it will be more visual
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef __GNUG__
|
#ifdef __GNUG__
|
||||||
@@ -47,19 +44,20 @@ WX_DEFINE_ARRAY(wxThread *, wxArrayThread);
|
|||||||
// Define a new application type
|
// Define a new application type
|
||||||
class MyApp : public wxApp
|
class MyApp : public wxApp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// all the threads currently alive - as soon as the thread terminates, it's
|
virtual bool OnInit();
|
||||||
// removed from the array
|
|
||||||
wxArrayThread m_threads;
|
|
||||||
|
|
||||||
// crit section protects access to all of the arrays below
|
public:
|
||||||
wxCriticalSection m_critsect;
|
// all the threads currently alive - as soon as the thread terminates, it's
|
||||||
public:
|
// removed from the array
|
||||||
bool OnInit();
|
wxArrayThread m_threads;
|
||||||
|
|
||||||
|
// crit section protects access to all of the arrays below
|
||||||
|
wxCriticalSection m_critsect;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create a new application object
|
// Create a new application object
|
||||||
IMPLEMENT_APP (MyApp)
|
IMPLEMENT_APP(MyApp)
|
||||||
|
|
||||||
// Define a new frame type
|
// Define a new frame type
|
||||||
class MyFrame: public wxFrame
|
class MyFrame: public wxFrame
|
||||||
@@ -88,7 +86,6 @@ private:
|
|||||||
// helper function - creates a new thread (but doesn't run it)
|
// helper function - creates a new thread (but doesn't run it)
|
||||||
MyThread *CreateThread();
|
MyThread *CreateThread();
|
||||||
|
|
||||||
|
|
||||||
// just some place to put our messages in
|
// just some place to put our messages in
|
||||||
wxTextCtrl *m_txtctrl;
|
wxTextCtrl *m_txtctrl;
|
||||||
|
|
||||||
@@ -152,7 +149,8 @@ void *MyThread::Entry()
|
|||||||
{
|
{
|
||||||
wxString text;
|
wxString text;
|
||||||
|
|
||||||
text.Printf("Thread 0x%x started.\n", GetID());
|
text.Printf("Thread 0x%x started (priority = %d).\n",
|
||||||
|
GetID(), GetPriority());
|
||||||
WriteText(text);
|
WriteText(text);
|
||||||
|
|
||||||
for ( m_count = 0; m_count < 10; m_count++ )
|
for ( m_count = 0; m_count < 10; m_count++ )
|
||||||
@@ -211,21 +209,21 @@ bool MyApp::OnInit()
|
|||||||
// Make a menubar
|
// Make a menubar
|
||||||
wxMenu *file_menu = new wxMenu;
|
wxMenu *file_menu = new wxMenu;
|
||||||
|
|
||||||
file_menu->Append(TEST_CLEAR, "&Clear log");
|
file_menu->Append(TEST_CLEAR, "&Clear log\tCtrl-L");
|
||||||
file_menu->AppendSeparator();
|
file_menu->AppendSeparator();
|
||||||
file_menu->Append(TEST_ABOUT, "&About");
|
file_menu->Append(TEST_ABOUT, "&About");
|
||||||
file_menu->AppendSeparator();
|
file_menu->AppendSeparator();
|
||||||
file_menu->Append(TEST_QUIT, "E&xit");
|
file_menu->Append(TEST_QUIT, "E&xit\tAlt-X");
|
||||||
wxMenuBar *menu_bar = new wxMenuBar;
|
wxMenuBar *menu_bar = new wxMenuBar;
|
||||||
menu_bar->Append(file_menu, "&File");
|
menu_bar->Append(file_menu, "&File");
|
||||||
|
|
||||||
wxMenu *thread_menu = new wxMenu;
|
wxMenu *thread_menu = new wxMenu;
|
||||||
thread_menu->Append(TEST_START_THREAD, "&Start a new thread");
|
thread_menu->Append(TEST_START_THREAD, "&Start a new thread\tCtrl-N");
|
||||||
thread_menu->Append(TEST_START_THREADS, "Start &many threads at once");
|
thread_menu->Append(TEST_START_THREADS, "Start &many threads at once");
|
||||||
thread_menu->Append(TEST_STOP_THREAD, "S&top a running thread");
|
thread_menu->Append(TEST_STOP_THREAD, "S&top a running thread\tCtrl-S");
|
||||||
thread_menu->AppendSeparator();
|
thread_menu->AppendSeparator();
|
||||||
thread_menu->Append(TEST_PAUSE_THREAD, "&Pause a running thread");
|
thread_menu->Append(TEST_PAUSE_THREAD, "&Pause a running thread\tCtrl-P");
|
||||||
thread_menu->Append(TEST_RESUME_THREAD, "&Resume suspended thread");
|
thread_menu->Append(TEST_RESUME_THREAD, "&Resume suspended thread\tCtrl-R");
|
||||||
menu_bar->Append(thread_menu, "&Thread");
|
menu_bar->Append(thread_menu, "&Thread");
|
||||||
frame->SetMenuBar(menu_bar);
|
frame->SetMenuBar(menu_bar);
|
||||||
|
|
||||||
@@ -285,7 +283,19 @@ void MyFrame::OnStartThreads(wxCommandEvent& WXUNUSED(event) )
|
|||||||
// first create them all...
|
// first create them all...
|
||||||
for ( n = 0; n < count; n++ )
|
for ( n = 0; n < count; n++ )
|
||||||
{
|
{
|
||||||
threads.Add(CreateThread());
|
wxThread *thr = CreateThread();
|
||||||
|
|
||||||
|
// we want to show the effect of SetPriority(): the first thread will
|
||||||
|
// have the lowest priority, the second - the highest, all the rest
|
||||||
|
// the normal one
|
||||||
|
if ( n == 0 )
|
||||||
|
thr->SetPriority(WXTHREAD_MIN_PRIORITY);
|
||||||
|
else if ( n == 1 )
|
||||||
|
thr->SetPriority(WXTHREAD_MAX_PRIORITY);
|
||||||
|
else
|
||||||
|
thr->SetPriority(WXTHREAD_DEFAULT_PRIORITY);
|
||||||
|
|
||||||
|
threads.Add(thr);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString msg;
|
wxString msg;
|
||||||
|
Reference in New Issue
Block a user