#endif // wxUSE_STARTUP_TIPS
#if wxUSE_PROGRESSDLG
+#if wxUSE_STOPWATCH && wxUSE_LONGLONG
+ #include <wx/datetime.h> // wxDateTime
+#endif
+
#include "wx/progdlg.h"
#endif // wxUSE_PROGRESSDLG
EVT_FIND_CLOSE(wxID_ANY, MyFrame::OnFindDialog)
#endif // wxUSE_FINDREPLDLG
+ EVT_MENU(DIALOGS_REQUEST, MyFrame::OnRequestUserAttention)
+
EVT_MENU(wxID_EXIT, MyFrame::OnExit)
END_EVENT_TABLE()
file_menu->Append(wxID_ANY,_T("&Modal/Modeless"),modal_menu);
#endif // USE_MODAL_PRESENTATION
+ file_menu->Append(DIALOGS_REQUEST, _T("&Request user attention\tCtrl-R"));
+
file_menu->AppendSeparator();
file_menu->Append(wxID_EXIT, _T("E&xit\tAlt-X"));
m_clrData.SetChooseFull(true);
for (int i = 0; i < 16; i++)
{
- m_clrData.SetCustomColour(i, wxColour(i*16, i*16, i*16));
+ m_clrData.SetCustomColour(
+ i,
+ wxColour(
+ (unsigned char)(i*16),
+ (unsigned char)(i*16),
+ (unsigned char)(i*16)
+ )
+ );
}
#endif // wxUSE_COLOURDLG
}
#endif // wxUSE_COLOURDLG
+#if USE_COLOURDLG_GENERIC
+void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event))
+{
+ m_clrData.SetColour(myCanvas->GetBackgroundColour());
+
+ //FIXME:TODO:This has no effect...
+ m_clrData.SetChooseFull(true);
+
+ for (int i = 0; i < 16; i++)
+ {
+ wxColour colour(
+ (unsigned char)(i*16),
+ (unsigned char)(i*16),
+ (unsigned char)(i*16)
+ );
+ m_clrData.SetCustomColour(i, colour);
+ }
+
+ wxGenericColourDialog *dialog = new wxGenericColourDialog(this, &m_clrData);
+ if (dialog->ShowModal() == wxID_OK)
+ {
+ m_clrData = dialog->GetColourData();
+ myCanvas->SetBackgroundColour(m_clrData.GetColour());
+ myCanvas->ClearBackground();
+ myCanvas->Refresh();
+ }
+ dialog->Destroy();
+}
+#endif // USE_COLOURDLG_GENERIC
+
#if wxUSE_FONTDLG
void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
{
}
#endif // wxUSE_FONTDLG
-#if USE_COLOURDLG_GENERIC
-void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event))
-{
- wxColourData data;
- data.SetChooseFull(true);
- for (int i = 0; i < 16; i++)
- {
- wxColour colour(i*16, i*16, i*16);
- data.SetCustomColour(i, colour);
- }
-
- wxGenericColourDialog *dialog = new wxGenericColourDialog(this, &data);
- if (dialog->ShowModal() == wxID_OK)
- {
- wxColourData retData = dialog->GetColourData();
- wxColour col = retData.GetColour();
-// wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID);
- myCanvas->SetBackgroundColour(col);
- myCanvas->ClearBackground();
- myCanvas->Refresh();
- }
- dialog->Destroy();
-}
-#endif // USE_COLOURDLG_GENERIC
-
#if USE_FONTDLG_GENERIC
void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) )
{
_T("Password entry dialog"),
wxEmptyString,
this);
- if ( !!pwd )
+ if ( !pwd.empty() )
{
wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd.c_str()),
_T("Got password"), wxOK | wxICON_INFORMATION, this);
}
#endif // wxUSE_STARTUP_TIPS
+void MyFrame::OnRequestUserAttention(wxCommandEvent& WXUNUSED(event))
+{
+ wxLogStatus(_T("Sleeping for 3 seconds to allow you to switch to another window"));
+
+ wxSleep(3);
+
+ RequestUserAttention(wxUSER_ATTENTION_ERROR);
+}
+
void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) )
{
Close(true);
void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) )
{
+ #if wxUSE_STOPWATCH && wxUSE_LONGLONG
+ // check the performance
+ int countrandomnumbers = 0, count = 0;
+ wxTimeSpan tsTest(0,0,0,250);
+ wxDateTime DT2, DT1 = wxDateTime::UNow();
+ srand(0);
+ while(1)
+ {
+ rand();
+ ++countrandomnumbers;
+ if ( countrandomnumbers == 1000 )
+ {
+ srand(0);
+ countrandomnumbers = 0;
+ ++count;
+ DT2 = wxDateTime::UNow();
+ wxTimeSpan ts = DT2.Subtract( DT1 );
+ if ( ts.IsLongerThan( tsTest ) )
+ {
+ break;
+ }
+ }
+ }
+ const int max = 40 * count;
+ #else
static const int max = 10;
+ #endif // wxUSE_STOPWATCH && wxUSE_LONGLONG
wxProgressDialog dialog(_T("Progress dialog example"),
_T("An informative message"),
max, // range
this, // parent
wxPD_CAN_ABORT |
+ wxPD_CAN_SKIP |
wxPD_APP_MODAL |
// wxPD_AUTO_HIDE | -- try this as well
wxPD_ELAPSED_TIME |
wxPD_ESTIMATED_TIME |
- wxPD_REMAINING_TIME);
+ wxPD_REMAINING_TIME |
+ wxPD_SMOOTH);
bool cont = true;
- for ( int i = 0; i <= max; i++ )
+ bool skip = false;
+ // each skip will move progress about quarter forward
+ for ( int i = 0; i <= max; i = wxMin(i+(skip?int(max/4):1), max+1), skip = false )
{
+ #if wxUSE_STOPWATCH && wxUSE_LONGLONG
+ // do (almost) the same operations as we did for the performance test
+ srand(0);
+ for ( int j = 0; j < 1000; j++ )
+ {
+ rand();
+ if ( j == 999 )
+ {
+ DT2 = wxDateTime::UNow();
+ wxTimeSpan ts = DT2.Subtract( DT1 );
+ if ( ts.IsLongerThan( tsTest ) )
+ {
+ // nothing to do
+ }
+ }
+ }
+ #else
wxSleep(1);
+ #endif
+
+ wxString msg;
+
if ( i == max )
{
- cont = dialog.Update(i, _T("That's all, folks!"));
+ msg = _T("That's all, folks!");
}
- else if ( i == max / 2 )
+ else if ( i > max / 2 )
{
- cont = dialog.Update(i, _T("Only a half left (very long message)!"));
+ msg = _T("Only a half left (very long message)!");
}
- else
+
+#if wxUSE_STOPWATCH && wxUSE_LONGLONG
+ if ( (i % (max/100)) == 0 ) // // only 100 updates, this makes it much faster
{
- cont = dialog.Update(i);
+ cont = dialog.Update(i, msg, &skip);
}
+#else
+ cont = dialog.Update(i, msg, &skip);
+#endif
if ( !cont )
{
wxYES_NO | wxICON_QUESTION) == wxYES )
break;
+ cont = true;
dialog.Resume();
}
}