]> git.saurik.com Git - wxWidgets.git/commitdiff
Add a possibility to show a progress dialog on dialog sample startup.
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 10 Sep 2010 17:25:35 +0000 (17:25 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 10 Sep 2010 17:25:35 +0000 (17:25 +0000)
Add a command line option to the dialogs sample to allow testing of different
wxProgressDialog styles more easily. This also tests for showing them before
the main event loop is started (see r65499).

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65502 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/doxygen/mainpages/samples.h
samples/dialogs/dialogs.cpp
samples/dialogs/dialogs.h

index ae268507bcf20990be8723db1f0c46597af49f54..29807d67ffda7bf83ae653dd2eecc5580f9a26f7 100644 (file)
@@ -301,6 +301,11 @@ wxDebugReportUpload will report an error.
 This sample shows how to use the common dialogs available from wxWidgets. These
 dialogs are described in detail in the @ref overview_cmndlg.
 
+In addition to the dialogs accessible from the sample menus, you can also run
+it with a <code>--progress=style</code> command line option to show a
+wxProgressDialog with the given style (try 0 for the default style) on program
+startup, before the main window is shown.
+
 @sampledir{dialogs}
 
 @section page_samples_dialup Dialup Sample
index 3abb1361392fac9dcb1611bab7a3d538bf6e02d1..53fd1a8c467de54afb47bd2ff2c72c93091a9ad2 100644 (file)
@@ -277,12 +277,63 @@ BEGIN_EVENT_TABLE(StdButtonSizerDialog, wxDialog)
     EVT_RADIOBUTTON(wxID_ANY, StdButtonSizerDialog::OnEvent)
 END_EVENT_TABLE()
 
+#if wxUSE_CMDLINE_PARSER
+
+#include "wx/cmdline.h"
+
+static const char *PROGRESS_SWITCH = "progress";
+
+void MyApp::OnInitCmdLine(wxCmdLineParser& parser)
+{
+    wxApp::OnInitCmdLine(parser);
+
+    parser.AddOption("", PROGRESS_SWITCH,
+                     "Style for the startup progress dialog (wxPD_XXX)",
+                     wxCMD_LINE_VAL_NUMBER);
+}
+
+bool MyApp::OnCmdLineParsed(wxCmdLineParser& parser)
+{
+    if ( !wxApp::OnCmdLineParsed(parser) )
+        return false;
+
+    parser.Found(PROGRESS_SWITCH, &m_startupProgressStyle);
+
+    return true;
+}
+
+#endif // wxUSE_CMDLINE_PARSER
+
 // `Main program' equivalent, creating windows and returning main app frame
 bool MyApp::OnInit()
 {
     if ( !wxApp::OnInit() )
         return false;
 
+#if wxUSE_PROGRESSDLG
+    if ( m_startupProgressStyle != -1 )
+    {
+        // Show a test progress dialog before the main event loop is started:
+        // it should still work.
+        const int PROGRESS_COUNT = 100;
+        wxProgressDialog dlg
+                         (
+                            "Progress in progress",
+                            "Please wait, starting...",
+                            PROGRESS_COUNT,
+                            NULL,
+                            m_startupProgressStyle
+                         );
+        for ( int i = 0; i <= PROGRESS_COUNT; i++ )
+        {
+            if ( !dlg.Update(i) )
+                break;
+
+            wxMilliSleep(50);
+        }
+    }
+#endif // wxUSE_PROGRESSDLG
+
 #if wxUSE_IMAGE
     wxInitAllImageHandlers();
 #endif
index d63cd1717b47eea6a5ff57014e81421833ff03a2..71a1f53b61bc36935e322c5ee28e098f05916e2b 100644 (file)
@@ -115,12 +115,26 @@ public:
 class MyApp: public wxApp
 {
 public:
+    MyApp() { m_startupProgressStyle = -1; }
+
     virtual bool OnInit();
 
+#if wxUSE_CMDLINE_PARSER
+    virtual void OnInitCmdLine(wxCmdLineParser& parser);
+    virtual bool OnCmdLineParsed(wxCmdLineParser& parser);
+#endif // wxUSE_CMDLINE_PARSER
+
 protected:
 #if wxUSE_LOG
     virtual wxAppTraits *CreateTraits() { return new MyAppTraits; }
 #endif // wxUSE_LOG
+
+private:
+    // Flag set to a valid value if command line option "progress" is used,
+    // this allows testing of wxProgressDialog before the main event loop is
+    // started. If this option is not specified it is set to -1 by default
+    // meaning that progress dialog shouldn't be shown at all.
+    long m_startupProgressStyle;
 };
 
 #if USE_MODAL_PRESENTATION