X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/33bcca32a9b96a52a2fa1dede65ee113ec934aba..f4bb632cde9cc60fa89f173f0d33c5881794cc68:/samples/dialogs/dialogs.cpp?ds=inline diff --git a/samples/dialogs/dialogs.cpp b/samples/dialogs/dialogs.cpp index 9533cbfbbe..8e551bdc64 100644 --- a/samples/dialogs/dialogs.cpp +++ b/samples/dialogs/dialogs.cpp @@ -41,6 +41,10 @@ #endif // wxUSE_STARTUP_TIPS #if wxUSE_PROGRESSDLG +#if wxUSE_STOPWATCH && wxUSE_LONGLONG + #include // wxDateTime +#endif + #include "wx/progdlg.h" #endif // wxUSE_PROGRESSDLG @@ -181,6 +185,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) 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() @@ -342,6 +348,8 @@ bool MyApp::OnInit() 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")); @@ -380,7 +388,14 @@ MyFrame::MyFrame(wxWindow *parent, 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 @@ -406,6 +421,36 @@ void MyFrame::ChooseColour(wxCommandEvent& WXUNUSED(event) ) } #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) ) { @@ -431,31 +476,6 @@ 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) ) { @@ -555,7 +575,7 @@ void MyFrame::PasswordEntry(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); @@ -919,6 +939,15 @@ void MyFrame::ShowTip(wxCommandEvent& WXUNUSED(event)) } #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); @@ -928,35 +957,91 @@ void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) ) 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 ) { @@ -965,6 +1050,7 @@ void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) ) wxYES_NO | wxICON_QUESTION) == wxYES ) break; + cont = true; dialog.Resume(); } }