Kirix Support Forums

Patch enabling checking if back and forward are possible

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

Patch enabling checking if back and forward are possible

Postby HansDR on Fri Apr 29, 2011 3:56 am

I wanted to be able to enable/disable the backward and forward icons based on whether or not those actions were possible, so here's a small patch that extracts this information directly from XULRunner.

In webcontrol.h, add the following methods to wxWebControl:
Code: Select all
    bool CanGoForward() const;
    bool CanGoBack() const;


In webcontrol.cpp, add the method implementations:
Code: Select all
// (METHOD) wxWebControl::CanGoForward
// Description: Returns true if it is possible to navigate forward,
// and false otherwise.
//
// Syntax: bool wxWebControl::CanGoForward()
//
// Remarks:
//
// Returns: True if it is possible to navigate forward

bool wxWebControl::CanGoForward() const
{
    PRBool canGoForward;
    m_ptrs->m_web_navigation->GetCanGoForward(&canGoForward);
    return (canGoForward == PR_TRUE);
}

// (METHOD) wxWebControl::CanGoBackward
// Description: Returns true if it is possible to navigate backward,
// and false otherwise.
//
// Syntax: bool wxWebControl::CanGoBackward()
//
// Remarks:
//
// Returns: True if it is possible to navigate backward

bool wxWebControl::CanGoBack() const
{
    PRBool canGoBackward;
    m_ptrs->m_web_navigation->GetCanGoBack(&canGoBackward);
    return (canGoBackward == PR_TRUE);
}


Probably the best place to use this is the application's wxEVT_WEB_LOCATIONCHANGE event handler, e.g.:
Code: Select all
void BrowserWindow::onLocationChange(wxWebEvent& event)
{
    browserToolBar->EnableTool(wxID_BACKWARD, webControl->CanGoBack());
    browserToolBar->EnableTool(wxID_FORWARD, webControl->CanGoForward());
    browserToolBar->Refresh();
}


The refresh at the end of the event handler is because the wxAUIToolBar wasn't refreshing automatically.

Hans
HansDR
Registered User
 
Posts: 2
Joined: Thu Apr 28, 2011 4:01 pm

Return to wxWebConnect Patches & Modifications