Kirix Support Forums

Progress in status bar

Please post any wxWebConnect patches or modifications you've created here. Thanks!

Progress in status bar

Postby ngpaton on Thu Aug 27, 2009 8:58 am

Hi,

Below is a patch to show a progress bar in the status bar. Note it also includes my other changes (excluding makefiles) for running on Linux.

Code: Select all
diff -uNr webconnect.orig/testapp/testapp.cpp webconnect/testapp/testapp.cpp
--- webconnect.orig/testapp/testapp.cpp   2009-07-08 02:32:50.000000000 +0100
+++ webconnect/testapp/testapp.cpp   2009-08-27 14:32:56.000000000 +0100
@@ -124,6 +124,7 @@
     void OnStatusText(wxWebEvent& evt);
     void OnStatusChange(wxWebEvent& evt);
     void OnStateChange(wxWebEvent& evt);
+    void OnProgressChange(wxWebEvent& evt);
     void OnLocationChange(wxWebEvent& evt);
     void OnTitleChange(wxWebEvent& evt);
     void OnShowContextMenu(wxWebEvent& evt);
@@ -147,6 +148,8 @@
     // web control and url bar
     wxWebControl* m_browser;
     wxComboBox* m_urlbar;
+    // Progress bar
+    wxGauge *     m_progress;

     // default locations
     wxString m_uri_home;
@@ -174,18 +177,27 @@

     bool OnInit()
     {
-        // Locate the XULRunner engine; the following call will look for
-        // a directory named "xr"
-        wxString xulrunner_path = FindXulRunner(wxT("xr"));
+        // Locate the XULRunner engine;
+        wxString xulrunner_path;
+#if defined (_WIN32)
+        // the following call will look for a directory named "xr"
+        xulrunner_path = FindXulRunner(wxT("xr"));
         if (xulrunner_path.IsEmpty())
         {
             wxMessageBox(wxT("Could not find xulrunner directory"));
             return false;
-        }   
+        }
+#elif defined (__linux__)
+        //xulrunner_path = wxT("/usr/lib/xulrunner");
+        xulrunner_path = wxT("/usr/lib/xulrunner-1.9.0.13");
+#elif
+# error TBD find xulrunner dir for this platform
+#endif   
     
         // Locate some common paths and initialize the control with
         // the plugin paths; add these common plugin directories to
         // MOZ_PLUGIN_PATH
+#if defined (_WIN32)
         wxString program_files_dir;
         ::wxGetEnv(wxT("ProgramFiles"), &program_files_dir);
         if (program_files_dir.Length() == 0 || program_files_dir.Last() != '\\')
@@ -194,6 +206,12 @@
         wxString dir = program_files_dir;
         dir += wxT("Mozilla Firefox\\plugins");
         wxWebControl::AddPluginPath(dir);
+#elif defined (__linux__)
+        //wxWebControl::AddPluginPath(wxT("/usr/lib/xulrunner-addons/plugins"));
+        wxWebControl::AddPluginPath(wxT("/usr/lib/firefox-addons/plugins"));
+#elif
+# error TBD add plugin dirs for this platform
+#endif

         // to install the flash plugin automatically, if it exists,
         // add a path to the flash location; for example, on windows,
@@ -307,6 +325,7 @@
     EVT_WEB_STATUSTEXT(wxID_WEB, MyFrame::OnStatusText)
     EVT_WEB_STATUSCHANGE(wxID_WEB, MyFrame::OnStatusChange)
     EVT_WEB_STATECHANGE(wxID_WEB, MyFrame::OnStateChange)
+    EVT_WEB_PROGRESSCHANGE(wxID_WEB, MyFrame::OnProgressChange)
     EVT_WEB_LOCATIONCHANGE(wxID_WEB, MyFrame::OnLocationChange)
     EVT_WEB_TITLECHANGE(wxID_WEB, MyFrame::OnTitleChange)
     EVT_WEB_SHOWCONTEXTMENU(wxID_WEB, MyFrame::OnShowContextMenu)
@@ -388,9 +407,15 @@
     mb->Append(help_menu, _("&Help"));
     SetMenuBar(mb);

-    CreateStatusBar();
-    GetStatusBar()->SetStatusText(_("Ready"));
-
+    CreateStatusBar(2);
+    wxStatusBar * statusBar = GetStatusBar();
+    statusBar->SetStatusText(_("Ready"));
+    // Create the progress gauge for the status bar
+    // Will be positioned in the OnSize event handler
+    m_progress = new wxGauge(statusBar, wxID_ANY, 1, wxDefaultPosition, wxDefaultSize, wxGA_HORIZONTAL | wxGA_SMOOTH);
+    // Set panel sizes (fixed width for progress)
+    int statusWidths[2] = {-1, 100};
+    statusBar->SetStatusWidths(2, statusWidths);

     // create the main toolbar
     wxAuiToolBar* toolbar = new wxAuiToolBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
@@ -400,7 +425,7 @@
     toolbar->AddTool(ID_GoForward, wxT("Go Forward"), wxArtProvider::GetBitmap(wxART_GO_FORWARD));
     toolbar->AddTool(ID_GoHome, wxT("Go Home"), wxArtProvider::GetBitmap(wxART_GO_HOME));

-    m_urlbar = new wxComboBox(toolbar, wxID_URL, wxT(""), wxPoint(0,0), wxSize(850,18));   
+    m_urlbar = new wxComboBox(toolbar, wxID_URL, wxT(""), wxPoint(0,0), wxSize(850,-1));   
     toolbar->AddControl(m_urlbar, wxT("Location"));

     toolbar->Realize();
@@ -481,6 +506,10 @@

void MyFrame::OnSize(wxSizeEvent& evt)
{
+    // Resize the progress gauge
+    wxRect rect;
+    GetStatusBar()->GetFieldRect(1, rect);
+    m_progress->SetSize(rect.x + 2, rect.y + 2, rect.width - 4, rect.height - 4);
}

void MyFrame::OnEraseBackground(wxEraseEvent& evt)
@@ -872,6 +901,22 @@
         status_bar->SetStatusText(status_text);
}

+void MyFrame::OnProgressChange(wxWebEvent& evt)
+{
+    if (evt.m_maxTotalProgress >= evt.m_curTotalProgress)
+    {
+        //m_progress->SetValue(0);
+        m_progress->SetRange(evt.m_maxTotalProgress);
+        m_progress->SetValue(evt.m_curTotalProgress);
+    }
+    else
+    {
+        // m_maxTotalProgress not known (-1) or
+        // a problem with max less than cur
+        m_progress->SetValue(0);
+    }
+}
+
void MyFrame::OnLocationChange(wxWebEvent& evt)
{
     // set the url bar
@@ -936,7 +981,7 @@
     // get the filename
     wxString filename = evt.GetFilename();
     wxMessageDialog dlg(this,
-                        wxString::Format(wxT("Would you like to download %s?"), filename),
+                        wxString::Format(wxT("Would you like to download %s?"), filename.c_str()),
                         wxT("Download File"),
                         wxYES_NO);

@@ -1004,6 +1049,9 @@
void MyFrame::OnDOMContentLoaded(wxWebEvent& evt)
{
     m_dom_contentloaded = true;
+
+    // Clear progress bar
+    m_progress->SetValue(0);
}

void MyFrame::SetUrlBarValue(const wxString& str)
diff -uNr webconnect.orig/webconnect/webcontrol.cpp webconnect/webconnect/webcontrol.cpp
--- webconnect.orig/webconnect/webcontrol.cpp   2009-07-06 15:24:00.000000000 +0100
+++ webconnect/webconnect/webcontrol.cpp   2009-08-27 13:17:43.000000000 +0100
@@ -38,6 +38,7 @@
DEFINE_EVENT_TYPE(wxEVT_WEB_STATUSTEXT)
DEFINE_EVENT_TYPE(wxEVT_WEB_STATUSCHANGE)
DEFINE_EVENT_TYPE(wxEVT_WEB_STATECHANGE)
+DEFINE_EVENT_TYPE(wxEVT_WEB_PROGRESSCHANGE)
DEFINE_EVENT_TYPE(wxEVT_WEB_SHOWCONTEXTMENU)
DEFINE_EVENT_TYPE(wxEVT_WEB_CREATEBROWSER)
DEFINE_EVENT_TYPE(wxEVT_WEB_LEFTDOWN)
@@ -536,6 +537,17 @@
                                               PRInt32 curTotalProgress,
                                               PRInt32 maxTotalProgress)
{
+    if (!m_wnd)
+        return NS_OK;
+
+    wxWebEvent evt(wxEVT_WEB_PROGRESSCHANGE, m_wnd->GetId());
+    evt.SetEventObject(m_wnd);
+    evt.m_curSelfProgress  = curSelfProgress;
+    evt.m_maxSelfProgress  = maxSelfProgress;
+    evt.m_curTotalProgress = curTotalProgress;
+    evt.m_maxTotalProgress = maxTotalProgress;
+    m_wnd->GetEventHandler()->ProcessEvent(evt);
+
     return NS_OK;
}

diff -uNr webconnect.orig/webconnect/webcontrol.h webconnect/webconnect/webcontrol.h
--- webconnect.orig/webconnect/webcontrol.h   2009-07-08 04:26:00.000000000 +0100
+++ webconnect/webconnect/webcontrol.h   2009-08-27 13:16:38.000000000 +0100
@@ -629,7 +629,13 @@
     int m_download_action;
     wxString m_download_action_path;
     wxWebProgressBase* m_download_listener;
-   
+
+    // wxEVT_WEB_PROGRESSCHANGE related values
+    wxInt32   m_curSelfProgress;
+    wxInt32   m_maxSelfProgress;
+    wxInt32   m_curTotalProgress;
+    wxInt32   m_maxTotalProgress;
+
#ifndef SWIG
private:
     DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxWebEvent)
@@ -646,6 +652,7 @@
     DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_WEB_STATECHANGE, 0)
     DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_WEB_STATUSCHANGE, 0)
     DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_WEB_STATUSTEXT, 0)
+    DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_WEB_PROGRESSCHANGE, 0)
     DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_WEB_SHOWCONTEXTMENU, 0)
     DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_WEB_LEFTDOWN, 0)
     DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_WEB_MIDDLEDOWN, 0)
@@ -689,6 +696,9 @@
#define EVT_WEB_STATUSTEXT(winid, func) \
    wx__DECLARE_EVT1(wxEVT_WEB_STATUSTEXT, winid, wxWebEventHandler(func))

+#define EVT_WEB_PROGRESSCHANGE(winid, func) \
+   wx__DECLARE_EVT1(wxEVT_WEB_PROGRESSCHANGE, winid, wxWebEventHandler(func))
+
#define EVT_WEB_SHOWCONTEXTMENU(winid, func) \
    wx__DECLARE_EVT1(wxEVT_WEB_SHOWCONTEXTMENU, winid, wxWebEventHandler(func))


Cheers

Nigel
ngpaton
Registered User
 
Posts: 11
Joined: Wed Aug 19, 2009 4:42 am

Return to wxWebConnect Patches & Modifications